View gist:4565837
// In your GameState class extending StarlingState (working for State and Away3DState too).
override public function initialize():void {
// The group property specifies the depth sorting: objects placed in group 1 will be behind objects placed in group 2.
// Here both objects have the same group, therefore the first added will be behind the second.
var cs1:CitrusSprite = new CitrusSprite("cs1", {x:100, y:100, group:5, view:new Quad(100, 100, 0xFF0000)});
View gist:4060507
// 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() {
_levels = [[Level1, "levels/A1/LevelA1.swf"], [Level2, "levels/A2/LevelA2.swf"]];
View gist:4030440
// In the Main class :
public function Main() {
state = new TiledMapGameState();
setTimeout(otherState, 4000);
private function otherState():void {
View gist:4024623
// Arts specified by a path to a file like "levels/coin.png" are loaded under the hood by the Citrus Engine.
//You can follow the progression in your GameState :
//add a mask to the game to hide objects loading in the background
_maskDuringLoading = new Quad(stage.stageWidth, stage.stageHeight);
// create a textfield to show the loading %
_percentTF = new TextField(400, 200, "", "ArialMT");
View gist:4024296
// In a GameState, the parameters are the object to follow, the offset, the bounds and the easing., new Point(stage.stageWidth / 2, stage.stageHeight / 2), new Rectangle(0, 0, 1550, 450), new Point(.25, .05));
// You can add more interactivity :
stage.addEventListener(MouseEvent.MOUSE_WHEEL, _mouseWheel);
CitrusEngine.getInstance().input.keyboard.addKeyAction("rotate", Keyboard.X);
private function _mouseWheel(mEvt:MouseEvent):void {
if ( > 0)
View gist:4024256
//In your Main class :
public function Main() {
levelManager = new LevelManager(ALevel);
levelManager.applicationDomain = ApplicationDomain.currentDomain; // to be able to load your SWF level on iOS
levelManager.levels = [[Level1, "levels/A1/LevelA1.swf"], [Level2, "levels/A2/LevelA2.swf"]];
levelManager.gotoLevel(); //load the first level, you can change the index. You can also call it later.
View gist:4024068
// In the Main class, register the sounds :
sound.addSound("Hurt", {sound:"sounds/hurt.mp3"});
sound.addSound("Collect", {sound:"sounds/collect.mp3"});
sound.addSound("Song", {sound:"sounds/song.mp3",timesToPlay:-1});
// In your GameState play them when needed :
private function handleHeroTakeDamage():void {
View gist:4024051
//In the Main class add this command. It will pause and unpause the game :
this.console.addCommand("pause", pauseGame);
private function pauseGame():void {
this.playing = !this.playing;
//Using parameters :
this.console.addCommand("goto", goto);
View gist:4022129
// In a state class :
//Here we use Box2D. /!\ Don't forget that your _hero must have its touchable property set to true!
var draggableHeroArt:DisplayObject = view.getArt(_hero) as DisplayObject;
draggableHeroArt.addEventListener(MouseEvent.MOUSE_DOWN, _handleGrab);
stage.addEventListener(MouseEvent.MOUSE_UP, _handleRelease);
private function _handleGrab(mEvt:MouseEvent):void {
View gist:4022074
// If you want to use Blitting view instead of the SpriteView override this method in your State class :
//Make sure and call this override to specify Blitting mode.
override protected function createView():CitrusView {
return new BlittingView(this);
//Using Starling or Away3D you don't need to override the view since it uses StarlingState/Away3D which already specify StarlingView/Away3DView.
//Don't forget that your Main class should extend StarlingCitrusEngine or Away3DCitrusEngine.