44/// <reference path="../components/animation/AnimationManager.ts" />
55/// <reference path="../components/sprite/Texture.ts" />
66/// <reference path="../components/sprite/Physics.ts" />
7+ /// <reference path="../physics/Body.ts" />
78
89/**
910* Phaser - Sprite
@@ -21,10 +22,10 @@ module Phaser {
2122 * @param [x] {number} the initial x position of the sprite.
2223 * @param [y] {number} the initial y position of the sprite.
2324 * @param [key] {string} Key of the graphic you want to load for this sprite.
24- * @param [width] {number} The width of the object.
25- * @param [height] {number} The height of the object.
25+ * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
2626 */
27- constructor ( game : Game , x ?: number = 0 , y ?: number = 0 , key ?: string = null , width ?: number = 16 , height ?: number = 16 ) {
27+ //constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) {
28+ constructor ( game : Game , x ?: number = 0 , y ?: number = 0 , key ?: string = null , bodyType ?: number = Phaser . Types . BODY_DISABLED ) {
2829
2930 this . game = game ;
3031 this . type = Phaser . Types . SPRITE ;
@@ -35,7 +36,8 @@ module Phaser {
3536 this . visible = true ;
3637 this . alive = true ;
3738
38- this . frameBounds = new Rectangle ( x , y , width , height ) ;
39+ // We give it a default size of 16x16 but when the texture loads (if given) it will reset this
40+ this . frameBounds = new Rectangle ( x , y , 16 , 16 ) ;
3941 this . scrollFactor = new Phaser . Vec2 ( 1 , 1 ) ;
4042
4143 this . x = x ;
@@ -50,17 +52,11 @@ module Phaser {
5052 this . scale = new Phaser . Vec2 ( 1 , 1 ) ;
5153 this . skew = new Phaser . Vec2 ( 0 , 0 ) ;
5254
53- this . physics = new Phaser . Components . Physics ( this ) ;
54- this . physics . shape . physics = this . physics ;
55+ // If a texture has been given the body will be set to that size, otherwise 16x16
56+ this . body = new Phaser . Physics . Body ( this , bodyType ) ;
5557
5658 }
5759
58- /**
59- * Rotation angle of this object.
60- * @type {number }
61- */
62- private _rotation : number = 0 ;
63-
6460 /**
6561 * Reference to the main game object
6662 */
@@ -97,9 +93,9 @@ module Phaser {
9793 public alive : bool ;
9894
9995 /**
100- * Sprite physics.
96+ * Sprite physics body .
10197 */
102- public physics : Phaser . Components . Physics ;
98+ public body : Phaser . Physics . Body ;
10399
104100 /**
105101 * The texture used to render the Sprite.
@@ -160,26 +156,26 @@ module Phaser {
160156 public z : number = 0 ;
161157
162158 /**
163- * This value is added to the rotation of the Sprite.
159+ * This value is added to the angle of the Sprite.
164160 * For example if you had a sprite graphic drawn facing straight up then you could set
165- * rotationOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
161+ * angleOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
166162 * @type {number }
167163 */
168- public rotationOffset : number = 0 ;
164+ public angleOffset : number = 0 ;
169165
170166 /**
171- * The rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
167+ * The angle of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
172168 */
173- public get rotation ( ) : number {
174- return this . _rotation ;
169+ public get angle ( ) : number {
170+ return this . body . angle ;
175171 }
176172
177173 /**
178- * Set the rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
174+ * Set the angle of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
179175 * The value is automatically wrapped to be between 0 and 360.
180176 */
181- public set rotation ( value : number ) {
182- this . _rotation = this . game . math . wrap ( value , 360 , 0 ) ;
177+ public set angle ( value : number ) {
178+ this . body . angle = this . game . math . wrap ( value , 360 , 0 ) ;
183179 }
184180
185181 /**
@@ -234,7 +230,7 @@ module Phaser {
234230 this . frameBounds . x = this . x ;
235231 this . frameBounds . y = this . y ;
236232
237- if ( this . modified == false && ( ! this . scale . equals ( 1 ) || ! this . skew . equals ( 0 ) || this . rotation != 0 || this . rotationOffset != 0 || this . texture . flippedX || this . texture . flippedY ) )
233+ if ( this . modified == false && ( ! this . scale . equals ( 1 ) || ! this . skew . equals ( 0 ) || this . angle != 0 || this . angleOffset != 0 || this . texture . flippedX || this . texture . flippedY ) )
238234 {
239235 this . modified = true ;
240236 }
@@ -253,7 +249,7 @@ module Phaser {
253249 public postUpdate ( ) {
254250
255251 this . animations . update ( ) ;
256- this . physics . update ( ) ;
252+ this . body . postUpdate ( ) ;
257253
258254 /*
259255 if (this.worldBounds != null)
@@ -287,15 +283,11 @@ module Phaser {
287283 }
288284 }
289285
290- this.collisionMask.update();
291-
292286 if (this.inputEnabled)
293287 {
294288 this.updateInput();
295289 }
296290
297- this.wasTouching = this.touching;
298- this.touching = Collision.NONE;
299291 */
300292
301293 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 )
0 commit comments