33/// <reference path="../core/Rectangle.ts" />
44/// <reference path="../core/Circle.ts" />
55/// <reference path="../gameobjects/Sprite.ts" />
6+ /// <reference path="RectangleUtils.ts" />
67
78/**
89* Phaser - SpriteUtils
@@ -154,28 +155,27 @@ module Phaser {
154155 *
155156 * @return Whether or not the point overlaps this object.
156157 */
157- /*
158- static overlapsPoint(point: Point, inScreenSpace: bool = false, camera: Camera = null): bool {
158+ static overlapsPoint ( sprite : Sprite , point : Point , inScreenSpace : bool = false , camera : Camera = null ) : bool {
159159
160160 if ( ! inScreenSpace )
161161 {
162- return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
162+ return Phaser . RectangleUtils . containsPoint ( sprite . body . bounds , point ) ;
163+ //return (point.x > sprite.x) && (point.x < sprite.x + sprite.width) && (point.y > sprite.y) && (point.y < sprite.y + sprite.height);
163164 }
164165
165166 if ( camera == null )
166167 {
167- camera = this._game .camera;
168+ camera = sprite . game . camera ;
168169 }
169170
170- var X : number = point.x - camera.scroll.x;
171- var Y : number = point.y - camera.scroll.y;
171+ // var x : number = point.x - camera.scroll.x;
172+ // var y : number = point.y - camera.scroll.y;
172173
173- this.getScreenXY(this._point, camera);
174+ // this.getScreenXY(this._point, camera);
174175
175- return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
176+ // return (x > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
176177
177178 }
178- */
179179
180180 /**
181181 * Check and see if this object is currently on screen.
@@ -240,28 +240,6 @@ module Phaser {
240240 }
241241 */
242242
243- /**
244- * Check whether this object is visible in a specific camera rectangle.
245- * @param camera {Rectangle} The rectangle you want to check.
246- * @return {boolean } Return true if bounds of this sprite intersects the given rectangle, otherwise return false.
247- */
248- static inCamera ( camera : Rectangle , cameraOffsetX : number , cameraOffsetY : number ) : bool {
249-
250- // Object fixed in place regardless of the camera scrolling? Then it's always visible
251- if ( this . scrollFactor . x == 0 && this . scrollFactor . y == 0 )
252- {
253- return true ;
254- }
255-
256- this . _dx = ( this . frameBounds . x - camera . x ) ;
257- this . _dy = ( this . frameBounds . y - camera . y ) ;
258- this . _dw = this . frameBounds . width * this . scale . x ;
259- this . _dh = this . frameBounds . height * this . scale . y ;
260-
261- return ( camera . right > this . _dx ) && ( camera . x < this . _dx + this . _dw ) && ( camera . bottom > this . _dy ) && ( camera . y < this . _dy + this . _dh ) ;
262-
263- }
264-
265243 /**
266244 * Handy for reviving game objects.
267245 * Resets their existence flags and position.
@@ -283,6 +261,19 @@ module Phaser {
283261
284262 }
285263
264+ static setOriginToCenter ( sprite : Sprite , fromFrameBounds : bool = true , fromBody ?: bool = false ) {
265+
266+ if ( fromFrameBounds )
267+ {
268+ sprite . origin . setTo ( sprite . frameBounds . halfWidth , sprite . frameBounds . halfHeight ) ;
269+ }
270+ else if ( fromBody )
271+ {
272+ sprite . origin . setTo ( sprite . body . bounds . halfWidth , sprite . body . bounds . halfHeight ) ;
273+ }
274+
275+ }
276+
286277 /**
287278 * Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
288279 * in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
0 commit comments