Last active
October 12, 2015 12:07
-
-
Save alamboley/4024296 to your computer and use it in GitHub Desktop.
How to set up a camera (Citrus Engine recipe)
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) | |
_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