11/// <reference path="../Game.ts" />
2+ /// <reference path="../core/Vec2.ts" />
23/// <reference path="../core/Rectangle.ts" />
34/// <reference path="../components/animation/AnimationManager.ts" />
45/// <reference path="../components/sprite/Texture.ts" />
@@ -34,19 +35,23 @@ module Phaser {
3435 this . alive = true ;
3536
3637 this . frameBounds = new Rectangle ( x , y , width , height ) ;
37- this . origin = new Phaser . Vec2 ( 0 , 0 ) ;
3838 this . scrollFactor = new Phaser . Vec2 ( 1 , 1 ) ;
39- this . scale = new Phaser . Vec2 ( 1 , 1 ) ;
4039
4140 this . x = x ;
4241 this . y = y ;
43- this . z = 0 ;
42+ this . z = 0 ; // not used yet
4443
45- this . texture = new Phaser . Components . Texture ( this , key , game . stage . canvas , game . stage . context ) ;
44+ this . animations = new Phaser . Components . AnimationManager ( this ) ;
45+ this . texture = new Phaser . Components . Texture ( this , key ) ;
4646
4747 this . width = this . frameBounds . width ;
4848 this . height = this . frameBounds . height ;
4949
50+ // Transform related (if we add any more then move to a component)
51+ this . origin = new Phaser . Vec2 ( this . width / 2 , this . height / 2 ) ;
52+ this . scale = new Phaser . Vec2 ( 1 , 1 ) ;
53+ this . skew = new Phaser . Vec2 ( 0 , 0 ) ;
54+
5055 }
5156
5257 /**
@@ -99,6 +104,12 @@ module Phaser {
99104 */
100105 public texture : Phaser . Components . Texture ;
101106
107+ /**
108+ * This manages animations of the sprite. You can modify animations though it. (see AnimationManager)
109+ * @type AnimationManager
110+ */
111+ public animations : Phaser . Components . AnimationManager ;
112+
102113 /**
103114 * The frame boundary around this Sprite.
104115 * For non-animated sprites this matches the loaded texture dimensions.
@@ -111,6 +122,16 @@ module Phaser {
111122 */
112123 public scale : Phaser . Vec2 ;
113124
125+ /**
126+ * Skew the Sprite along the x and y axis. A skew value of 0 is no skew.
127+ */
128+ public skew : Phaser . Vec2 ;
129+
130+ /**
131+ * A boolean representing if the Sprite has been modified in any way via a scale, rotate, flip or skew.
132+ */
133+ public modified : bool = false ;
134+
114135 /**
115136 * The influence of camera movement upon the Sprite.
116137 */
@@ -159,6 +180,34 @@ module Phaser {
159180 this . _rotation = this . game . math . wrap ( value , 360 , 0 ) ;
160181 }
161182
183+ /**
184+ * Set the animation frame by frame number.
185+ */
186+ public set frame ( value : number ) {
187+ this . animations . frame = value ;
188+ }
189+
190+ /**
191+ * Get the animation frame number.
192+ */
193+ public get frame ( ) : number {
194+ return this . animations . frame ;
195+ }
196+
197+ /**
198+ * Set the animation frame by frame name.
199+ */
200+ public set frameName ( value : string ) {
201+ this . animations . frameName = value ;
202+ }
203+
204+ /**
205+ * Get the animation frame name.
206+ */
207+ public get frameName ( ) : string {
208+ return this . animations . frameName ;
209+ }
210+
162211 /**
163212 * Pre-update is called right before update() on each object in the game loop.
164213 */
@@ -169,6 +218,11 @@ module Phaser {
169218
170219 //this.collisionMask.preUpdate();
171220
221+ if ( this . modified == false && ( ! this . scale . equals ( 1 ) || ! this . skew . equals ( 0 ) || this . rotation != 0 || this . rotationOffset != 0 || this . texture . flippedX || this . texture . flippedY ) )
222+ {
223+ this . modified = true ;
224+ }
225+
172226 }
173227
174228 /**
@@ -182,9 +236,9 @@ module Phaser {
182236 */
183237 public postUpdate ( ) {
184238
185- /*
186239 this . animations . update ( ) ;
187240
241+ /*
188242 if (this.moves)
189243 {
190244 this.updateMotion();
@@ -232,6 +286,11 @@ module Phaser {
232286 this.touching = Collision.NONE;
233287 */
234288
289+ if ( this . modified == true && this . scale . equals ( 1 ) && this . skew . equals ( 0 ) && this . rotation == 0 && this . rotationOffset == 0 && this . texture . flippedX == false && this . texture . flippedY == false )
290+ {
291+ this . modified = false ;
292+ }
293+
235294 }
236295
237296 /**
0 commit comments