所以我正在关注Slick 2D上的thenewboston教程。我完全像他说的那样加载图像:
private org.newdawn.slick.Image playNow;
...
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
...
playNow = new org.newdawn.slick.Image("res/playNow.png");
这是我的Eclipse项目树:
这是它给我的输出:
Tue Jul 03 09:31:53 PDT 2012 INFO:Slick Build #274
Tue Jul 03 09:31:53 PDT 2012 INFO:LWJGL Version: 2.8.5
Tue Jul 03 09:31:53 PDT 2012 INFO:OriginalDisplayMode: 1366 x 768 x 32 @60Hz
Tue Jul 03 09:31:53 PDT 2012 INFO:TargetDisplayMode: 640 x 360 x 0 @0Hz
Tue Jul 03 09:31:53 PDT 2012 INFO:Starting display 640x360
Tue Jul 03 09:31:53 PDT 2012 INFO:Use Java PNG Loader = true
Tue Jul 03 09:31:53 PDT 2012 INFO:Controllers not available
Exception in thread "main" java.lang.RuntimeException: Resource not found: res/playNow.png
at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169)
at org.newdawn.slick.Image.<init>(Image.java:196)
at org.newdawn.slick.Image.<init>(Image.java:170)
at org.newdawn.slick.Image.<init>(Image.java:158)
at org.newdawn.slick.Image.<init>(Image.java:136)
at net.sourceforge.whowantsakookie.hamblaster.Menu.init(Menu.java:21)
at net.sourceforge.whowantsakookie.hamblaster.Game.initStatesList(Game.java:20)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:164)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
at net.sourceforge.whowantsakookie.hamblaster.Game.main(Game.java:31)
本教程位于here
我正如教程所说的那样做,这对他在视频中起作用。在此先感谢:)
答案 0 :(得分:1)
没问题,“res”文件夹与“src”文件所在的文件夹在同一个文件夹中!
将包含所有图片的“res”文件夹移动到程序中的“src / net.sourceforge.whowant /”文件夹/包中。
在您的程序中,您将使用
加载它playNow = new org.newdawn.slick.Image("res/playNow.png");
希望这有帮助! :)