Skip to content

Instantly share code, notes, and snippets.

@alamboley
Created November 6, 2012 12:00
Show Gist options
  • Save alamboley/4024256 to your computer and use it in GitHub Desktop.
Save alamboley/4024256 to your computer and use it in GitHub Desktop.
How to use the Level Manager (Citrus Engine recipe)
//In your Main class :
public function Main() {
levelManager = new LevelManager(ALevel);
levelManager.onLevelChanged.add(_onLevelChanged);
levelManager.levels = [[Level1, "levels/A1/LevelA1.swf"], [Level2, "levels/A2/LevelA2.swf"]];
levelManager.gotoLevel();
}
private function _onLevelChanged(lvl:ALevel):void {
state = lvl;
lvl.lvlEnded.add(_nextLevel);
lvl.restartLevel.add(_restartLevel);
}
private function _nextLevel():void {
levelManager.nextLevel();
}
private function _restartLevel():void {
state = levelManager.currentLevel as IState;
}
//Note that you should create an abstract clas : Level1 and Level2 extends ALevel which extends the State class.
@feresr
Copy link

feresr commented Sep 27, 2014

Thanks for this!, I see you've not called the 'setupStarling()' method, is that ok?

@alamboley
Copy link
Author

Here I'm using State, not StarlingState so we're on the display list ;)

@keops232000
Copy link

Hy there i am a new flash builder developer.
I have a little question..can you put a link of how to make an import from flash pro to builder to a level made in flash pro? Or some tutorials to create levels in flash pro and use in builder

thanks

@prmichaelsen
Copy link

Critically important for anyone targeting Starling (just spent four hours trying to workaround a missing Starling context because I didn't understand the nature of my problem): your ALevel should extend StarlingState, not State. You will still need to call setUpStarling in your main. Like this:

public class ALevel extends StarlingState { ... }
public class Main extends StarlingCitrusEngine { 
    public function Main() {
        setUpStarling(true);
        ...
    }
    ...
}

Hopefully this will save you the headache I just dealt with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment