Animation and Input related fixes

This commit is contained in:
Richard Davey
2013-08-16 00:14:57 +01:00
parent 619b8415ed
commit f76ba6840f
10 changed files with 103 additions and 36 deletions
+10
View File
@@ -37,6 +37,16 @@ module Phaser {
*/
constructor(callbackContext, parent: string = '', width: number = 800, height: number = 600, preloadCallback = null, createCallback = null, updateCallback = null, renderCallback = null, destroyCallback = null) {
// Single instance check
if (window['PhaserGlobal'].singleInstance)
{
if (Phaser.GAMES.length > 0)
{
console.log('Phaser detected an instance of this game already running, aborting');
return;
}
}
this.id = Phaser.GAMES.push(this) - 1;
this.callbackContext = callbackContext;
+1 -1
View File
@@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<ProjectGuid>{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}</ProjectGuid>
<ProjectGuid>{A90BE60F-CAEA-4747-904A-CDB097BA2459}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<OutputPath>bin</OutputPath>
+7 -2
View File
@@ -155,14 +155,19 @@ module Phaser {
* @param frameRate {number} FrameRate you want to specify instead of using default.
* @param loop {bool} Whether or not the animation is looped or just plays once.
*/
public play(frameRate: number = null, loop: bool = false) {
public play(frameRate: number = null, loop: bool = null) {
if (frameRate !== null)
{
this.delay = 1000 / frameRate;
}
this.looped = loop;
if (loop !== null)
{
// If they set a new loop value then use it, otherwise use the default set on creation
this.looped = loop;
}
this.isPlaying = true;
this.isFinished = false;
+1 -1
View File
@@ -174,7 +174,7 @@ module Phaser.Components {
* @param frameRate {number} FrameRate you want to specify instead of using default.
* @param loop {bool} Whether or not the animation is looped or just plays once.
*/
public play(name: string, frameRate: number = null, loop: bool = false): Animation {
public play(name: string, frameRate: number = null, loop: bool = null): Phaser.Animation {
if (this._anims[name])
{
+2 -2
View File
@@ -64,7 +64,7 @@ module Phaser {
this.transform.setCache();
this.body = new Phaser.Physics.Body(this, 0);
//this.body = new Phaser.Physics.Body(this, 0);
this.outOfBounds = false;
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
@@ -363,7 +363,7 @@ module Phaser {
this.checkBounds();
this.transform.centerOn(this.body.aabb.pos.x, this.body.aabb.pos.y);
//this.transform.centerOn(this.body.aabb.pos.x, this.body.aabb.pos.y);
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
{
+7 -3
View File
@@ -295,7 +295,9 @@ module Phaser.Components {
}
else
{
return SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
//return SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
//return SpriteUtils.overlapsXY(this._parent, pointer.screenX, pointer.screenY);
return SpriteUtils.overlapsPointer(this._parent, pointer);
}
}
@@ -317,7 +319,8 @@ module Phaser.Components {
}
else if (this._pointerData[pointer.id].isOver == true)
{
if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
//if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
if (SpriteUtils.overlapsPointer(this._parent, pointer))
{
this._pointerData[pointer.id].x = pointer.x - this._parent.x;
this._pointerData[pointer.id].y = pointer.y - this._parent.y;
@@ -409,7 +412,8 @@ module Phaser.Components {
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
// Only release the InputUp signal if the pointer is still over this sprite
if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
//if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
if (SpriteUtils.overlapsPointer(this._parent, pointer))
{
//console.log('releasedHandler: ' + Date.now());
this._parent.events.onInputUp.dispatch(this._parent, pointer);
+1 -1
View File
@@ -12,7 +12,7 @@ module Phaser {
export class Keyboard {
constructor(game: Game) {
constructor(game: Phaser.Game) {
this.game = game;
+28 -5
View File
@@ -167,12 +167,35 @@ module Phaser {
}
*/
public static overlapsPointer(sprite:Phaser.Sprite, pointer: Phaser.Pointer): bool {
if (sprite.transform.scrollFactor.equals(1))
{
// We can do a world vs. world check
return Phaser.SpriteUtils.overlapsXY(sprite, pointer.worldX, pointer.worldY);
}
else if (sprite.transform.scrollFactor.equals(0))
{
// scroll factor 0 means a screen view check, as the sprite will be absolutely positioned
return Phaser.SpriteUtils.overlapsXY(sprite, pointer.x, pointer.y);
}
else
{
// If the sprite has a scroll factor other than 0 or 1 then we need to work out
// what the pointers scroll factor values would be
var px: number = pointer.worldX * sprite.transform.scrollFactor.x;
var py: number = pointer.worldY * sprite.transform.scrollFactor.y;
return Phaser.SpriteUtils.overlapsXY(sprite, px, py);
}
}
/**
* Checks to see if the given x and y coordinates overlaps this <code>Sprite</code>, taking scaling and rotation into account.
* The coordinates must be given in world space, not local or camera space.
*
* @method overlapsXY
* @param {Sprite} sprite The Sprite to check. It will take scaling and rotation into account.
* @param {Sprite} sprite The Sprite to check. It will take scaling and rotation into account, but NOT scroll factor.
* @param {Number} x The x coordinate in world space.
* @param {Number} y The y coordinate in world space.
* @return {bool} Whether or not the point overlaps this object.
@@ -180,10 +203,10 @@ module Phaser {
public static overlapsXY(sprite: Phaser.Sprite, x: number, y: number): bool {
// if rotation == 0 then just do a rect check instead!
if (sprite.transform.rotation == 0)
{
return Phaser.RectangleUtils.contains(sprite.worldView, x, y);
}
//if (sprite.transform.rotation == 0)
//{
// return Phaser.RectangleUtils.contains(sprite.worldView, x, y);
//}
if ((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0)
{
+21 -10
View File
@@ -5088,7 +5088,7 @@ var Phaser;
if(this.enabled == false || this._parent.visible == false) {
return false;
} else {
return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
return Phaser.SpriteUtils.overlapsPointer(this._parent, pointer);
}
};
InputHandler.prototype.update = function (pointer) {
@@ -5099,7 +5099,7 @@ var Phaser;
if(this.draggable && this._draggedPointerID == pointer.id) {
return this.updateDrag(pointer);
} else if(this._pointerData[pointer.id].isOver == true) {
if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
this._pointerData[pointer.id].x = pointer.x - this._parent.x;
this._pointerData[pointer.id].y = pointer.y - this._parent.y;
return true;
@@ -5152,7 +5152,7 @@ var Phaser;
this._pointerData[pointer.id].isUp = true;
this._pointerData[pointer.id].timeUp = this.game.time.now;
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
this._parent.events.onInputUp.dispatch(this._parent, pointer);
} else {
if(this.useHandCursor) {
@@ -6929,11 +6929,14 @@ var Phaser;
});
Animation.prototype.play = function (frameRate, loop) {
if (typeof frameRate === "undefined") { frameRate = null; }
if (typeof loop === "undefined") { loop = false; }
if (typeof loop === "undefined") { loop = null; }
if(frameRate !== null) {
this.delay = 1000 / frameRate;
}
this.looped = loop;
if(loop !== null) {
console.log('play loop override', loop);
this.looped = loop;
}
this.isPlaying = true;
this.isFinished = false;
this._timeLastFrame = this.game.time.now;
@@ -6963,7 +6966,9 @@ var Phaser;
this._frameIndex = 0;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
this._parent.events.onAnimationLoop.dispatch(this._parent, this);
console.log('anim loop core');
} else {
console.log('anim complete core');
this.onComplete();
}
} else {
@@ -10693,7 +10698,6 @@ var Phaser;
this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
this.transform.setCache();
this.body = new Phaser.Physics.Body(this, 0);
this.outOfBounds = false;
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
this.scale = this.transform.scale;
@@ -10791,7 +10795,6 @@ var Phaser;
Sprite.prototype.postUpdate = function () {
this.animations.update();
this.checkBounds();
this.transform.centerOn(this.body.aabb.pos.x, this.body.aabb.pos.y);
if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
this.modified = false;
}
@@ -11940,10 +11943,18 @@ var Phaser;
out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
return out;
};
SpriteUtils.overlapsXY = function overlapsXY(sprite, x, y) {
if(sprite.transform.rotation == 0) {
return Phaser.RectangleUtils.contains(sprite.worldView, x, y);
SpriteUtils.overlapsPointer = function overlapsPointer(sprite, pointer) {
if(sprite.transform.scrollFactor.equals(1)) {
return Phaser.SpriteUtils.overlapsXY(sprite, pointer.worldX, pointer.worldY);
} else if(sprite.transform.scrollFactor.equals(0)) {
return Phaser.SpriteUtils.overlapsXY(sprite, pointer.x, pointer.y);
} else {
var px = pointer.worldX * sprite.transform.scrollFactor.x;
var py = pointer.worldY * sprite.transform.scrollFactor.y;
return Phaser.SpriteUtils.overlapsXY(sprite, px, py);
}
};
SpriteUtils.overlapsXY = function overlapsXY(sprite, x, y) {
if((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0) {
return false;
}
+25 -11
View File
@@ -5088,7 +5088,7 @@ var Phaser;
if(this.enabled == false || this._parent.visible == false) {
return false;
} else {
return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
return Phaser.SpriteUtils.overlapsPointer(this._parent, pointer);
}
};
InputHandler.prototype.update = function (pointer) {
@@ -5099,7 +5099,7 @@ var Phaser;
if(this.draggable && this._draggedPointerID == pointer.id) {
return this.updateDrag(pointer);
} else if(this._pointerData[pointer.id].isOver == true) {
if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
this._pointerData[pointer.id].x = pointer.x - this._parent.x;
this._pointerData[pointer.id].y = pointer.y - this._parent.y;
return true;
@@ -5152,7 +5152,7 @@ var Phaser;
this._pointerData[pointer.id].isUp = true;
this._pointerData[pointer.id].timeUp = this.game.time.now;
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
if(Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
this._parent.events.onInputUp.dispatch(this._parent, pointer);
} else {
if(this.useHandCursor) {
@@ -6929,11 +6929,13 @@ var Phaser;
});
Animation.prototype.play = function (frameRate, loop) {
if (typeof frameRate === "undefined") { frameRate = null; }
if (typeof loop === "undefined") { loop = false; }
if (typeof loop === "undefined") { loop = null; }
if(frameRate !== null) {
this.delay = 1000 / frameRate;
}
this.looped = loop;
if(loop !== null) {
this.looped = loop;
}
this.isPlaying = true;
this.isFinished = false;
this._timeLastFrame = this.game.time.now;
@@ -7054,7 +7056,7 @@ var Phaser;
};
AnimationManager.prototype.play = function (name, frameRate, loop) {
if (typeof frameRate === "undefined") { frameRate = null; }
if (typeof loop === "undefined") { loop = false; }
if (typeof loop === "undefined") { loop = null; }
if(this._anims[name]) {
if(this.currentAnim == this._anims[name]) {
if(this.currentAnim.isPlaying == false) {
@@ -10693,7 +10695,6 @@ var Phaser;
this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
this.transform.setCache();
this.body = new Phaser.Physics.Body(this, 0);
this.outOfBounds = false;
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
this.scale = this.transform.scale;
@@ -10791,7 +10792,6 @@ var Phaser;
Sprite.prototype.postUpdate = function () {
this.animations.update();
this.checkBounds();
this.transform.centerOn(this.body.aabb.pos.x, this.body.aabb.pos.y);
if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
this.modified = false;
}
@@ -11940,10 +11940,18 @@ var Phaser;
out.push(new Phaser.Point(sprite.x, sprite.y + sprite.height));
return out;
};
SpriteUtils.overlapsXY = function overlapsXY(sprite, x, y) {
if(sprite.transform.rotation == 0) {
return Phaser.RectangleUtils.contains(sprite.worldView, x, y);
SpriteUtils.overlapsPointer = function overlapsPointer(sprite, pointer) {
if(sprite.transform.scrollFactor.equals(1)) {
return Phaser.SpriteUtils.overlapsXY(sprite, pointer.worldX, pointer.worldY);
} else if(sprite.transform.scrollFactor.equals(0)) {
return Phaser.SpriteUtils.overlapsXY(sprite, pointer.x, pointer.y);
} else {
var px = pointer.worldX * sprite.transform.scrollFactor.x;
var py = pointer.worldY * sprite.transform.scrollFactor.y;
return Phaser.SpriteUtils.overlapsXY(sprite, px, py);
}
};
SpriteUtils.overlapsXY = function overlapsXY(sprite, x, y) {
if((x - sprite.transform.upperLeft.x) * (sprite.transform.upperRight.x - sprite.transform.upperLeft.x) + (y - sprite.transform.upperLeft.y) * (sprite.transform.upperRight.y - sprite.transform.upperLeft.y) < 0) {
return false;
}
@@ -14248,6 +14256,12 @@ var Phaser;
this.onDestroyCallback = null;
this.isBooted = false;
this.isRunning = false;
if(window['PhaserGlobal'].singleInstance) {
if(Phaser.GAMES.length > 0) {
console.log('Phaser detected an instance of this game already running, aborting');
return;
}
}
this.id = Phaser.GAMES.push(this) - 1;
this.callbackContext = callbackContext;
this.onPreloadCallback = preloadCallback;