@@ -2,8 +2,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
22
33 x = x || 0 ;
44 y = y || 0 ;
5- // if null we ought to set to the phaser logo or something :)
6- key = key || null ;
5+ key = key || null ; // if null we ought to set to the phaser logo or something :)
76 frame = frame || null ;
87
98 this . game = game ;
@@ -14,7 +13,6 @@ Phaser.Sprite = function (game, x, y, key, frame) {
1413 this . alive = true ;
1514
1615 this . group = null ;
17-
1816 this . name = '' ;
1917
2018 if ( key )
@@ -53,7 +51,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
5351 }
5452 else
5553 {
56- this . currentFrame = new Phaser . Animation . Frame ( x , y , width , height , '' , '' ) ;
54+ this . currentFrame = this . game . cache . getFrame ( key ) ;
5755 }
5856
5957 /**
@@ -111,13 +109,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
111109 width : this . currentFrame . sourceSizeW , height : this . currentFrame . sourceSizeH ,
112110
113111 // The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
114- // actualWidth: 0, actualHeight: 0,
115-
116- // The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
117- halfWidth : Math . floor ( this . currentFrame . sourceSizeW ) , halfHeight : Math . floor ( this . currentFrame . sourceSizeH ) ,
118-
119- // The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
120- // centerX: 0, centerY: 0,
112+ halfWidth : Math . floor ( this . currentFrame . sourceSizeW / 2 ) , halfHeight : Math . floor ( this . currentFrame . sourceSizeH / 2 ) ,
121113
122114 // The current frame details
123115 frameID : this . currentFrame . uuid , frameWidth : this . currentFrame . width , frameHeight : this . currentFrame . height ,
@@ -131,7 +123,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
131123
132124 // Corner point defaults
133125 this . offset = new Phaser . Point ;
134- this . center = new Phaser . Point ( Math . floor ( this . _cache . width / 2 ) , Math . floor ( this . _cache . height / 2 ) ) ;
126+ this . center = new Phaser . Point ( x + Math . floor ( this . _cache . width / 2 ) , y + Math . floor ( this . _cache . height / 2 ) ) ;
135127 this . topLeft = new Phaser . Point ( x , y ) ;
136128 this . topRight = new Phaser . Point ( x + this . _cache . width , y ) ;
137129 this . bottomRight = new Phaser . Point ( x + this . _cache . width , y + this . _cache . height ) ;
@@ -182,7 +174,7 @@ Phaser.Sprite.prototype.update = function() {
182174 {
183175 this . _cache . a00 = this . worldTransform [ 0 ] ; // scaleX a
184176 this . _cache . a01 = this . worldTransform [ 1 ] ; // skewY c
185- this . _cache . scaleX = Math . sqrt ( ( this . _cache . a00 * this . _cache . a00 ) + ( this . _cache . a01 * this . _cache . a01 ) ) ;
177+ this . _cache . scaleX = Math . sqrt ( ( this . _cache . a00 * this . _cache . a00 ) + ( this . _cache . a01 * this . _cache . a01 ) ) ; // round this off a bit?
186178 this . _cache . a01 *= - 1 ;
187179 this . _cache . dirty = true ;
188180 }
@@ -192,7 +184,7 @@ Phaser.Sprite.prototype.update = function() {
192184 {
193185 this . _cache . a10 = this . worldTransform [ 3 ] ; // skewX b
194186 this . _cache . a11 = this . worldTransform [ 4 ] ; // scaleY d
195- this . _cache . scaleY = Math . sqrt ( ( this . _cache . a10 * this . _cache . a10 ) + ( this . _cache . a11 * this . _cache . a11 ) ) ;
187+ this . _cache . scaleY = Math . sqrt ( ( this . _cache . a10 * this . _cache . a10 ) + ( this . _cache . a11 * this . _cache . a11 ) ) ; // round this off a bit?
196188 this . _cache . a10 *= - 1 ;
197189 this . _cache . dirty = true ;
198190 }
@@ -209,14 +201,16 @@ Phaser.Sprite.prototype.update = function() {
209201 {
210202 this . _cache . frameWidth = this . texture . frame . width ;
211203 this . _cache . frameHeight = this . texture . frame . height ;
204+ this . _cache . frameID = this . currentFrame . uuid ;
205+ this . _cache . dirty = true ;
212206 }
213207
214208 if ( this . _cache . dirty )
215209 {
216- this . _cache . width = this . currentFrame . sourceSizeW * this . _cache . scaleX ;
217- this . _cache . height = this . currentFrame . sourceSizeH * this . _cache . scaleY ;
218-
219- // this.getLocalPosition(this.center, this.x - (this.anchor.x * this. _cache.width), this.y - (this.anchor.y * this. _cache.height) );
210+ this . _cache . width = Math . floor ( this . currentFrame . sourceSizeW * this . _cache . scaleX ) ;
211+ this . _cache . height = Math . floor ( this . currentFrame . sourceSizeH * this . _cache . scaleY ) ;
212+ this . _cache . halfWidth = Math . floor ( this . _cache . width / 2 ) ;
213+ this . _cache . halfHeight = Math . floor ( this . _cache . height / 2 ) ;
220214
221215 this . _cache . id = 1 / ( this . _cache . a00 * this . _cache . a11 + this . _cache . a01 * - this . _cache . a10 ) ;
222216
@@ -249,10 +243,10 @@ Phaser.Sprite.prototype.update = function() {
249243 }
250244
251245 // Update our physics bounds
252- this . body . update ( ) ;
246+ this . body . update ( this . center . x , this . center . y , this . _cache . scaleX , this . _cache . scaleY ) ;
253247 }
254248
255- // Check our bounds
249+ this . body . updateMotion ( ) ;
256250
257251}
258252
@@ -262,8 +256,6 @@ Phaser.Sprite.prototype.updateBounds = function() {
262256
263257 this . offset . setTo ( this . _cache . a02 - ( this . anchor . x * this . _cache . width ) , this . _cache . a12 - ( this . anchor . y * this . _cache . height ) ) ;
264258
265- // this.getLocalPosition(this.center, this.x - (this.anchor.x * this._cache.width), this.y - (this.anchor.y * this._cache.height));
266-
267259 this . getLocalPosition ( this . center , this . offset . x + this . _cache . halfWidth , this . offset . y + this . _cache . halfHeight ) ;
268260 this . getLocalPosition ( this . topLeft , this . offset . x , this . offset . y ) ;
269261 this . getLocalPosition ( this . topRight , this . offset . x + this . _cache . width , this . offset . y ) ;
0 commit comments