/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { LoadingList.setDeferredLoading(true); new Sound("testdata/cbrown01.wav"); new Sound("testdata/engine.wav"); sound = new Sound("testdata/restart.ogg"); new Music("testdata/testloop.ogg"); music = new Music("testdata/SMB-X.XM"); new Image("testdata/cursor.png"); new Image("testdata/cursor.tga"); new Image("testdata/cursor.png"); new Image("testdata/cursor.png"); new Image("testdata/dungeontiles.gif"); new Image("testdata/logo.gif"); image = new Image("testdata/logo.tga"); new Image("testdata/logo.png"); new Image("testdata/rocket.png"); new Image("testdata/testpack.png"); font = new AngelCodeFont("testdata/demo.fnt", "testdata/demo_00.tga"); }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { if (nextResource != null) { g.drawString("Loading: "+nextResource.getDescription(), 100, 100); } int total = LoadingList.get().getTotalResources(); int loaded = LoadingList.get().getTotalResources() - LoadingList.get().getRemainingResources(); float bar = loaded / (float) total; g.fillRect(100,150,loaded*40,20); g.drawRect(100,150,total*40,20); if (started) { image.draw(100,200); font.drawString(100,500,"LOADING COMPLETE"); } }
public void init(GameContainer container, StateBasedGame game) throws SlickException { ConfigsManager.getInstance().applicateConfigs(); LoadingList.setDeferredLoading(true); DatasManager.getInstance().addFile("LivingEntity.name", new TrueTypeFont(new Font("Verdana", Font.BOLD, 12), true)); DatasManager.getInstance().addFile("TextEffect.damages", new TrueTypeFont(new Font("Verdana", Font.BOLD, 12), true)); DatasManager.getInstance().addFile("TextEffect.status", new TrueTypeFont(new Font("Verdana", Font.BOLD, 14), true)); DatasManager.getInstance().addFile("MouseCursor.default", new Image("res/images/cursors/default.png")); DatasManager.getInstance().addMap("test.tmx"); try { ResourcesManager.getInstance().loadResources(); } catch (Exception e) { throw new SlickException(e.getMessage()); } super.init(container, game); }
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException { super.update(container, game, delta); if (mResource != null) { try { mResource.load(); } catch (IOException e) { throw new SlickException("Failed to load: " + mResource.getDescription(), e); } mResource = null; } mRemaining = LoadingList.get().getRemainingResources(); mTotal = LoadingList.get().getTotalResources(); if (LoadingList.get().getRemainingResources() > 0) { mResource = LoadingList.get().getNext(); } else { ((Music)DatasManager.getInstance().getFile("Music.menu")).loop(); game.enterState(1, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } }
/** * Create a new deferred texture * * @param in The input stream from which to read the texture * @param resourceName The name to give the resource * @param flipped True if the image should be flipped * @param filter The filter to apply * @param trans The colour to defined as transparent */ public DeferredTexture(InputStream in, String resourceName, boolean flipped, int filter, int[] trans) { this.in = in; this.resourceName = resourceName; this.flipped = flipped; this.filter = filter; this.trans = trans; LoadingList.get().add(this); }
/** * Check if the target has been obtained already */ private void checkTarget() { if (target == null) { try { load(); LoadingList.get().remove(this); return; } catch (IOException e) { throw new RuntimeException("Attempt to use deferred texture before loading and resource not found: "+resourceName); } } }
/** * Create a new sound on request to load * * @param ref The location of the sound to load * @param type The type of sound to load * @param in The input stream to load from */ public DeferredSound(String ref, InputStream in, int type) { this.ref = ref; this.type = type; // nasty hack to detect when we're loading from a stream if (ref.equals(in.toString())) { this.in = in; } LoadingList.get().add(this); }
/** * Create a new deferred texture * * @param in The input stream from which to read the texture * @param resourceName The name to give the resource * @param flipped True if the image should be flipped * @param filter The filter to apply * @param trans The colour to defined as transparent */ public DeferredTexture(InputStream in, String resourceName, boolean flipped, int filter, @Nullable int[] trans) { this.in = in; this.resourceName = resourceName; this.flipped = flipped; this.filter = filter; this.trans = trans; LoadingList.get().add(this); }
/** * Check if the target has been obtained already */ private void checkTarget() { if (target == null) { try { load(); LoadingList.get().remove(this); } catch (IOException e) { throw new RuntimeException("Attempt to use deferred texture before loading and resource not found: "+resourceName); } } }