Skip to content

Instantly share code, notes, and snippets.

View alamboley's full-sized avatar

Aymeric Lamboley alamboley

View GitHub Profile
@alamboley
alamboley / gist:4565837
Last active December 11, 2015 07:19
How to manage deeply z-sorting (Citrus Engine recipe)
// 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);
@alamboley
alamboley / gist:4060507
Created November 12, 2012 16:58
How to use the AGameData class (Citrus Engine recipe)
// 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"]];
}
@alamboley
alamboley / gist:4030440
Created November 7, 2012 09:44
How to change or destroy State (Citrus Engine recipe)
// In the Main class :
public function Main() {
state = new TiledMapGameState();
setTimeout(otherState, 4000);
}
private function otherState():void {
@alamboley
alamboley / gist:4024623
Last active October 12, 2015 12:08
How to make a preloader (Citrus Engine recipe)
// 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);
@alamboley
alamboley / gist:4024296
Last active October 12, 2015 12:07
How to set up a camera (Citrus Engine recipe)
// 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)
@alamboley
alamboley / gist:4024256
Created November 6, 2012 12:00
How to use the Level Manager (Citrus Engine recipe)
//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.
}
@alamboley
alamboley / gist:4024068
Last active October 12, 2015 12:07
How to play sounds (Citrus Engine recipe)
// 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");
}
@alamboley
alamboley / gist:4024051
Created November 6, 2012 11:06
How to add commands to the console (Citrus Engine recipe)
//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);
@alamboley
alamboley / gist:4022129
Last active October 12, 2015 11:47
How to grab and drag physics objects (Citrus Engine recipe)
// 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 {
@alamboley
alamboley / gist:4022074
Created November 6, 2012 02:05
How to specify the view (Citrus Engine recipe)
// 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.