Skip to content

Instantly share code, notes, and snippets.

@alamboley
Last active October 12, 2015 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alamboley/4024296 to your computer and use it in GitHub Desktop.
Save alamboley/4024296 to your computer and use it in GitHub Desktop.
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)
_camera.setZoom(_camera.getZoom() + 0.1);
else if (e.delta < 0)
_camera.setZoom(_camera.getZoom() - 0.1);
}
override public function update(timeDelta:Number):void {
super.update(timeDelta);
if (CitrusEngine.getInstance().input.justDid("rotate"))
_camera.rotate(Math.PI / 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment