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
// Citrus object's view management is powerful: when a view is added to the object it is loaded and added to a template | |
// called SpriteArt which is a container of your art. This template allows to load external files thanks to their path. | |
// It works the same way with Starling. | |
var _hero:Hero = new Hero("my hero", {view:"myHero.swf"}); | |
// _hero.view refers to the path "myHero.swf" not to the swf loaded. | |
// If the view specified is a DisplayObject, you can directly make whatever you want on it (filter, blendMode, ect). | |
var _heroGraphic:SpriteArt = view.getArt(_hero) as SpriteArt; | |
// _heroGraphic is the container of the art. It will loads and display the art. Most often you will work with this. |
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
// Inside a class which extends CitrusObject e.g. CitrusSprite, APhysicsObjects... | |
kill = true; | |
// If you have an access to the variable of the object : | |
hero.kill = true; | |
// Or within a State class (the previous code works too) : | |
remove(hero); |
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
var coin:Coin = new Coin("coin", {view:"art.png", touchable:true}); | |
//Within your state class. Same process for Starling or Away3D | |
var coinArt:DisplayObject = view.getArt(coin) as DisplayObject; | |
coinArt.addEventListener(MouseEvent.CLICK, handleCoinClick); | |
private function handleCoinClick(e:MouseEvent):void | |
{ | |
var clickedCoin:Coin = view.getObjectFromArt(e.currentTarget) as Coin; |
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. |
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
//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 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 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 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
// 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); |
OlderNewer