Skip to content

Instantly share code, notes, and snippets.

@alamboley
Created November 12, 2012 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamboley/4060507 to your computer and use it in GitHub Desktop.
Save alamboley/4060507 to your computer and use it in GitHub Desktop.
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