Last active
August 29, 2015 14:02
-
-
Save ibilon/378a608de9c3410810a8 to your computer and use it in GitHub Desktop.
Resource management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main extends Engine | |
{ | |
override function init() | |
{ | |
// resources added in Engine are kept in memory | |
resources.addTexture("graphics/player.png"); | |
// if a Scene resources aren't all available push preloader on scene stack until they are | |
preloader = new MyCustomPreloadingScreen(); | |
scene = new Level1(); | |
} | |
} | |
class Level1 extends Scene | |
{ | |
var next : Scene; | |
override function assetsRequest() | |
{ | |
// resources added in Scene are removed at the end of the scene | |
// unless some other Scene has it loaded too (reference count) | |
resources.addTexture("graphics/badguy.png"); | |
resources.addTexture("graphics/background.png"); | |
resources.addFont("fonts/helvetica.ttf"); | |
} | |
override function begin() | |
{ | |
// called without showing the preloader | |
// if all resources are already loaded | |
// now can use the assets | |
new Image("graphics/player.png"); | |
new Image("graphics/badguy.png"); | |
// (...) | |
// preload next level | |
next = new Level2(); | |
next.preload(); | |
} | |
override function update() | |
{ | |
// at some point | |
resources.freeTexture("graphics/badguy.png"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment