这一节给大家讲解一下Citrus的关卡管理
package box2dstarling {
import starling.utils.AssetManager;
import box2dstarling.ALevel;
import box2dstarling.MyGameData;
import citrus.core.IState;
import citrus.core.starling.StarlingCitrusEngine;
import citrus.utils.LevelManager;
[SWF(frameRate="60")]
public class Main extends StarlingCitrusEngine {
public function Main() {
setUpStarling(true);
gameData = new MyGameData();
levelManager = new LevelManager(ALevel);
levelManager.onLevelChanged.add(_onLevelChanged);
levelManager.levels = gameData.levels;
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;
}
}
}
官方提供的Demo源代码
https://github.com/alamboley/Citrus-Engine-Examples/tree/master/src/box2dstarling
Citrus有自带的LoaderManager
citrus.utils.LevelManager提供了关卡管理功能,不过蛋疼的是LevelManager并未提供资源队列加载,以及加载进度读取功能,个人议改造一下这个类,以满足游戏的需求。