Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to use the AGameData class (Citrus Engine recipe)
// 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