Fixed the world drag issue across Sprite and Button.

This commit is contained in:
Richard Davey
2013-08-06 04:34:52 +01:00
parent a7873a3b74
commit 77cc3858d9
12 changed files with 83 additions and 133 deletions
+5 -6
View File
@@ -87,11 +87,10 @@ module Phaser {
* @param y {number} Y position of the new sprite.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
* @returns {Sprite} The newly created sprite object.
*/
public sprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DISABLED): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType));
public sprite(x: number, y: number, key?: string = '', frame? = null): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame));
}
public audio(key: string, volume?: number = 1, loop?: bool = false) {
@@ -109,9 +108,9 @@ module Phaser {
* @param [shapeType] The default body shape is either 0 for a Box or 1 for a Circle. See Sprite.body.addShape for custom shapes (polygons, etc)
* @returns {Sprite} The newly created sprite object.
*/
public physicsSprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC, shapeType?:number = 0): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType, shapeType));
}
//public physicsSprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC, shapeType?:number = 0): Sprite {
// return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType, shapeType));
//}
/**
* Create a new DynamicTexture with specific size.
+19 -12
View File
@@ -23,10 +23,8 @@ module Phaser {
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics)
* @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape)
*/
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, frame? = null, bodyType?: number = Phaser.Types.BODY_DISABLED, shapeType?:number = 0) {
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, frame? = null) {
this.game = game;
this.type = Phaser.Types.SPRITE;
@@ -69,13 +67,6 @@ module Phaser {
}
}
if (bodyType !== Phaser.Types.BODY_DISABLED)
{
//this.body = new Phaser.Physics.Body(this, bodyType, 0, 0, shapeType);
//this.game.physics.addBody(this.body);
//this.transform.origin.setTo(0.5, 0.5);
}
this.worldView = new Rectangle(x, y, this.width, this.height);
this.cameraView = new Rectangle(x, y, this.width, this.height);
@@ -334,8 +325,24 @@ module Phaser {
this.transform.update();
this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
if (this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0)
{
this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
}
else
{
this.worldView.x = this.x - (this.width * this.transform.origin.x);
}
if (this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0)
{
this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
}
else
{
this.worldView.y = this.y - (this.height * this.transform.origin.y);
}
this.worldView.width = this.width;
this.worldView.height = this.height;