This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In your GameState class extending StarlingState (working for State and Away3DState too). | |
override public function initialize():void { | |
super.initialize(); | |
// 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)}); | |
add(cs1); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"]]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the Main class : | |
public function Main() { | |
state = new TiledMapGameState(); | |
setTimeout(otherState, 4000); | |
} | |
private function otherState():void { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
addChild(_maskDuringLoading); | |
// create a textfield to show the loading % | |
_percentTF = new TextField(400, 200, "", "ArialMT"); | |
addChild(_percentTF); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In a GameState, the parameters are the object to follow, the offset, the bounds and the easing. | |
view.camera.setUp(hero, 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 (e.delta > 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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.onLevelChanged.add(_onLevelChanged); | |
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. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { | |
_ce.sound.playSound("Hurt"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
NewerOlder