The CitrusSprite

This is the primary class for creating graphical game objects. You should override this class to add logic to your game object such as a Spaceship, Hero. This is the equivalent of the Flash Sprite. It has common properties that are required for properly displaying and positioning objects. If you wish to use physics engine, take a look on the platformer kit.

A simple and powerful class

The CitrusSprite is a game object. It doesn't matter if you use Starling or the Flash display list, the CitrusSprite is a logical object which extend CitrusObject class and implement the ISpriteView interface.

To create a scrolling background:

var bg:CitrusSprite = new CitrusSprite("bg", {parallax:0.4, view:"background.png"});

The CitrusSprite via its update function (moving the object depending its velocity) uses an independent frame rate meaning the object will move at the same speed if the FPS targeted is 30 or 60.

You can quickly create your own Hero:

package {
	import citrus.objects.CitrusSprite;
	public class Hero extends CitrusSprite {
		public var accelerationX:Number = 200;
		public var accelerationY:Number = 100;
		public var inputChannel:uint = 0;
		public function Hero(name:String, params:Object = null) {
			super(name, params);
		override public function update(timeDelta:Number):void {
			if (_ce.input.isDoing("right", inputChannel))
				_velocity.x = accelerationX;
			if (_ce.input.isDoing("left", inputChannel))
				_velocity.x = -accelerationX;
			if (_ce.input.hasDone("left", inputChannel) || _ce.input.hasDone("right", inputChannel))
				_velocity.x = 0;
			if (_ce.input.isDoing("up", inputChannel))
				_velocity.y = -accelerationY;
			if (_ce.input.isDoing("down", inputChannel))
				_velocity.y = accelerationY;
			if (_ce.input.hasDone("up", inputChannel) || _ce.input.hasDone("down", inputChannel))
				_velocity.y = 0;
  citrus/citrussprite.txt · Last modified: 2013/02/04 17:17 by aymeric
Powered by DokuWiki