Created
November 12, 2012 16:58
-
-
Save alamboley/4060507 to your computer and use it in GitHub Desktop.
How to use the AGameData class (Citrus Engine recipe)
This file contains hidden or 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
// The AGameData class is an abstract (it should be extend) and dynamic class (you won't have problem | |
// to access its chidren properties, be careful your IDE may not indicate children properties). | |
public class MyGameData extends AGameData { | |
public function MyGameData() { | |
super(); | |
_levels = [[Level1, "levels/A1/LevelA1.swf"], [Level2, "levels/A2/LevelA2.swf"]]; | |
} | |
public function get levels():Array { | |
return _levels; | |
} | |
} | |
// In your Main class : | |
gameData = new MyGameData(); | |
// Combine it with the Level Manager (if used) : | |
levelManager.levels = gameData.levels; | |
// In your GameState you can access its properties this way : | |
var ce:CitrusEngine = CitrusEngine.getInstance(); | |
trace(ce.gameData.levels); | |
ce.gameData.lives = 4; | |
// When the data changes, it dispatches a Signal. Be sure to register it before any gameData's properties update. | |
_ce.gameData.dataChanged.add(onDataChanged); | |
private function onDataChanged(data:String, value:Object):void { | |
if (data == "lives" && value == 0) | |
trace("game over"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment