diff --git a/Phaser/components/animation/AnimationManager.ts b/Phaser/components/animation/AnimationManager.ts index 17a09cce..5fbbca8c 100644 --- a/Phaser/components/animation/AnimationManager.ts +++ b/Phaser/components/animation/AnimationManager.ts @@ -251,6 +251,8 @@ module Phaser.Components { this._parent.frameBounds.width = this.currentFrame.width; this._parent.frameBounds.height = this.currentFrame.height; + //this._parent.frameBounds.width = this.currentFrame.sourceSizeW; + //this._parent.frameBounds.height = this.currentFrame.sourceSizeH; this._frameIndex = this.currentFrame.index; } diff --git a/Phaser/components/animation/Frame.ts b/Phaser/components/animation/Frame.ts index 2a46f754..1c00d486 100644 --- a/Phaser/components/animation/Frame.ts +++ b/Phaser/components/animation/Frame.ts @@ -22,6 +22,8 @@ module Phaser { */ constructor(x: number, y: number, width: number, height: number, name: string) { + console.log('Creating Frame', name, 'x', x, 'y', y, 'width', width, 'height', height); + this.x = x; this.y = y; this.width = width; @@ -134,10 +136,10 @@ module Phaser { * @param trimmed {boolean} Whether this frame trimmed or not. * @param actualWidth {number} Actual width of this frame. * @param actualHeight {number} Actual height of this frame. - * @param destX {number} Destiny x position. - * @param destY {number} Destiny y position. - * @param destWidth {number} Destiny draw width. - * @param destHeight {number} Destiny draw height. + * @param destX {number} Destination x position. + * @param destY {number} Destination y position. + * @param destWidth {number} Destination draw width. + * @param destHeight {number} Destination draw height. */ public setTrim(trimmed: bool, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number) { diff --git a/Phaser/components/animation/FrameData.ts b/Phaser/components/animation/FrameData.ts index 033d3345..e54c8a7e 100644 --- a/Phaser/components/animation/FrameData.ts +++ b/Phaser/components/animation/FrameData.ts @@ -24,6 +24,7 @@ module Phaser { * Local frame container. */ private _frames: Frame[]; + /** * Local frameName<->index container. */ @@ -76,7 +77,7 @@ module Phaser { */ public getFrameByName(name: string): Frame { - if (this._frameNames[name] >= 0) + if (this._frameNames[name] !== '') { return this._frames[this._frameNames[name]]; } @@ -92,7 +93,7 @@ module Phaser { */ public checkFrameName(name: string): bool { - if (this._frameNames[name] >= 0) + if (this._frameNames[name]) { return true; } @@ -138,7 +139,7 @@ module Phaser { } /** - * Get all names of frames by giving their indexes. + * Get the frame indexes by giving the frame names. * @param [output] {number[]} result will be added into this array. * @return {number[]} Names of specific frames in an array. */ diff --git a/Phaser/components/sprite/Input.ts b/Phaser/components/sprite/Input.ts index bfe6c39d..26cf776b 100644 --- a/Phaser/components/sprite/Input.ts +++ b/Phaser/components/sprite/Input.ts @@ -223,6 +223,17 @@ module Phaser.Components { } + public reset() { + + this.enabled = false; + + for (var i = 0; i < 10; i++) + { + this._pointerData[i] = { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, timeDown: 0, timeUp: 0, downDuration: 0, isDragged: false }; + } + + } + public stop() { // Turning off @@ -239,69 +250,94 @@ module Phaser.Components { } + public checkPointerOver(pointer: Phaser.Pointer): bool { + + if (this.enabled == false || this._sprite.visible == false) + { + return false; + } + else + { + return RectangleUtils.contains(this._sprite.frameBounds, pointer.x, pointer.y); + } + + } + /** * Update */ public update(pointer: Phaser.Pointer): bool { - if (this.enabled == false) + if (this.enabled == false || this._sprite.visible == false) { return false; } - if (this.draggable && this._draggedPointerID == pointer.id) - { - this.updateDrag(pointer); - } - - if (RectangleUtils.contains(this._sprite.frameBounds, pointer.x, pointer.y)) + if (this.draggable && this._draggedPointerID == pointer.id) { - // { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, isDragged: false } - - this._pointerData[pointer.id].x = pointer.x - this._sprite.x; - this._pointerData[pointer.id].y = pointer.y - this._sprite.y; - - if (this._pointerData[pointer.id].isOver == false) - { - this._pointerData[pointer.id].isOver = true; - this._pointerData[pointer.id].isOut = false; - this._pointerData[pointer.id].timeOver = this.game.time.now; - - if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false) - { - this.game.stage.canvas.style.cursor = "pointer"; - } - - this._sprite.events.onInputOver.dispatch(this._sprite, pointer); - } - - return true; + return this.updateDrag(pointer); } - else + else if (this._pointerData[pointer.id].isOver == true) { - if (this._pointerData[pointer.id].isOver) + if (RectangleUtils.contains(this._sprite.frameBounds, pointer.x, pointer.y)) { - this._pointerData[pointer.id].isOver = false; - this._pointerData[pointer.id].isOut = true; - this._pointerData[pointer.id].timeOut = this.game.time.now; - - if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false) - { - this.game.stage.canvas.style.cursor = "default"; - } - - this._sprite.events.onInputOut.dispatch(this._sprite, pointer); + this._pointerData[pointer.id].x = pointer.x - this._sprite.x; + this._pointerData[pointer.id].y = pointer.y - this._sprite.y; + return true; + } + else + { + this._pointOutHandler(pointer); + return false; } - - return false; } } - public _touchedHandler(pointer: Pointer) { + public _pointerOverHandler(pointer: Pointer) { + + // { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, isDragged: false } + + if (this._pointerData[pointer.id].isOver == false) + { + this._pointerData[pointer.id].isOver = true; + this._pointerData[pointer.id].isOut = false; + this._pointerData[pointer.id].timeOver = this.game.time.now; + this._pointerData[pointer.id].x = pointer.x - this._sprite.x; + this._pointerData[pointer.id].y = pointer.y - this._sprite.y; + + if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false) + { + this.game.stage.canvas.style.cursor = "pointer"; + } + + this._sprite.events.onInputOver.dispatch(this._sprite, pointer); + } + + } + + public _pointOutHandler(pointer: Pointer) { + + this._pointerData[pointer.id].isOver = false; + this._pointerData[pointer.id].isOut = true; + this._pointerData[pointer.id].timeOut = this.game.time.now; + + if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false) + { + this.game.stage.canvas.style.cursor = "default"; + } + + this._sprite.events.onInputOut.dispatch(this._sprite, pointer); + + } + + public consumePointerEvent: bool = false; + + public _touchedHandler(pointer: Pointer): bool { if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) { + console.log('touchDown on', this._sprite.texture.cacheKey,this._sprite.frameName, this._sprite.frameBounds.width,this._sprite.frameBounds.height); this._pointerData[pointer.id].isDown = true; this._pointerData[pointer.id].isUp = false; this._pointerData[pointer.id].timeDown = this.game.time.now; @@ -309,13 +345,17 @@ module Phaser.Components { this._sprite.events.onInputDown.dispatch(this._sprite, pointer); // Start drag - if (this.draggable && this.isDragged == false && pointer.draggedObject == null) + //if (this.draggable && this.isDragged == false && pointer.targetObject == null) + if (this.draggable && this.isDragged == false) { this.startDrag(pointer); } } + // Consume the event? + return this.consumePointerEvent; + } public _releasedHandler(pointer: Pointer) { @@ -347,12 +387,12 @@ module Phaser.Components { /** * Updates the Pointer drag on this Sprite. */ - private updateDrag(pointer: Pointer):void + private updateDrag(pointer: Pointer):bool { if (pointer.isUp) { this.stopDrag(pointer); - return; + return false; } if (this.allowHorizontalDrag) @@ -380,6 +420,8 @@ module Phaser.Components { this._sprite.x = Math.floor(this._sprite.x / this.snapX) * this.snapX; this._sprite.y = Math.floor(this._sprite.y / this.snapY) * this.snapY; } + + return true; } /** @@ -516,7 +558,7 @@ module Phaser.Components { this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y); } - pointer.draggedObject = this._sprite; + //pointer.draggedObject = this._sprite; } @@ -535,7 +577,7 @@ module Phaser.Components { this._sprite.y = Math.floor(this._sprite.y / this.snapY) * this.snapY; } - pointer.draggedObject = null; + //pointer.draggedObject = null; } /** diff --git a/Phaser/core/Group.ts b/Phaser/core/Group.ts index fd9f6cea..bab0c8d4 100644 --- a/Phaser/core/Group.ts +++ b/Phaser/core/Group.ts @@ -253,6 +253,55 @@ module Phaser { } + /** + * Calls render on all members of this Group regardless of their visible status and also ignores the camera blacklist. + * Use this when the Group objects render to hidden canvases for example. + */ + public directRender(camera: Camera) { + + if (this.globalCompositeOperation) + { + this.game.stage.context.save(); + this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation; + } + + if (this.alpha > 0) + { + this._prevAlpha = this.game.stage.context.globalAlpha; + this.game.stage.context.globalAlpha = this.alpha; + } + + this._i = 0; + + while (this._i < this.length) + { + this._member = this.members[this._i++]; + + if (this._member != null && this._member.exists) + { + if (this._member.type == Types.GROUP) + { + this._member.directRender(camera); + } + else + { + this.game.renderer.renderGameObject(this._member); + } + } + } + + if (this.alpha > 0) + { + this.game.stage.context.globalAlpha = this._prevAlpha; + } + + if (this.globalCompositeOperation) + { + this.game.stage.context.restore(); + } + + } + /** * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow. */ diff --git a/Phaser/gameobjects/Sprite.ts b/Phaser/gameobjects/Sprite.ts index 6a096f5a..97c20a97 100644 --- a/Phaser/gameobjects/Sprite.ts +++ b/Phaser/gameobjects/Sprite.ts @@ -182,6 +182,11 @@ module Phaser { */ public z: number = 0; + /** + * Render iteration + */ + public renderOrderID: number = 0; + /** * This value is added to the angle of the Sprite. * For example if you had a sprite graphic drawn facing straight up then you could set @@ -326,6 +331,9 @@ module Phaser { */ public destroy() { + //this.input.destroy(); + + } /** diff --git a/Phaser/input/Input.ts b/Phaser/input/Input.ts index ea1cde0b..9cd629e0 100644 --- a/Phaser/input/Input.ts +++ b/Phaser/input/Input.ts @@ -23,7 +23,6 @@ module Phaser { constructor(game: Game) { this._game = game; - this._stack = []; this.mousePointer = new Pointer(this._game, 0); this.pointer1 = new Pointer(this._game, 1); @@ -57,11 +56,6 @@ module Phaser { */ private _game: Game; - /** - * Temporary click sorting stack - */ - private _stack; - /** * A vector object representing the previous position of the Pointer. * @property vector @@ -496,12 +490,6 @@ module Phaser { } - public addToStack(item) { - - this._stack.push(item); - - } - /** * Reset all of the Pointers and Input states * @method reset @@ -511,6 +499,7 @@ module Phaser { this.keyboard.reset(); + this.mousePointer.reset(); this.pointer1.reset(); this.pointer2.reset(); this.pointer3.reset(); @@ -525,8 +514,23 @@ module Phaser { this.currentPointers = 0; + for (var i = 0; i < this.totalTrackedObjects; i++) + { + this.inputObjects[i].input.reset(); + } + + this._game.stage.canvas.style.cursor = "default"; + + this.inputObjects.length = 0; + this.totalTrackedObjects = 0; + if (hard == true) { + this.onDown.dispose(); + this.onUp.dispose(); + this.onTap.dispose(); + this.onHold.dispose(); + this.onDown = new Phaser.Signal(); this.onUp = new Phaser.Signal(); this.onTap = new Phaser.Signal(); diff --git a/Phaser/input/Pointer.ts b/Phaser/input/Pointer.ts index 1284fee6..7cf4a944 100644 --- a/Phaser/input/Pointer.ts +++ b/Phaser/input/Pointer.ts @@ -65,6 +65,9 @@ module Phaser { */ private _nextDrop: number = 0; + // Monitor events outside of a state reset loop + private _stateReset: bool = false; + /** * The Pointer ID (a number between 1 and 10, 0 is reserved for the mouse pointer specifically) * @property id @@ -253,11 +256,11 @@ module Phaser { } /** - * The Game Object this Pointer is currently dragging. - * @property draggedObject + * The Game Object this Pointer is currently over / touching / dragging. + * @property targetObject * @type {Any} **/ - public draggedObject; + public targetObject = null; /** * Gets the X value of this Pointer in world coordinate space @@ -303,10 +306,6 @@ module Phaser { this._history.length = 0; - this.move(event); - - this.positionDown.setTo(this.x, this.y); - this.active = true; this.withinGame = true; this.isDown = true; @@ -314,6 +313,10 @@ module Phaser { this.timeDown = this.game.time.now; this._holdSent = false; + this.positionDown.setTo(this.x, this.y); + + this.move(event); + if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) { this.game.input.x = this.x * this.game.input.scaleX; @@ -321,6 +324,7 @@ module Phaser { this.game.input.onDown.dispatch(this); } + this._stateReset = false; this.totalTouches++; if (this.isMouse == false) @@ -328,6 +332,34 @@ module Phaser { this.game.input.currentPointers++; } + // Build our temporary click stack + /* + var _highestPriority = 0; + var _highestRenderID = 0; + var _highestRenderObject: number = -1; + + for (var i = 0; i < this.game.input.totalTrackedObjects; i++) + { + if (this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID) + { + _highestRenderID = this.game.input.inputObjects[i].renderOrderID; + _highestRenderObject = i; + } + } + + if (_highestRenderObject !== -1 && this._stateReset == false) + { + this.targetObject = this.game.input.inputObjects[_highestRenderObject]; + this.targetObject.input._touchedHandler(this); + //_highestRenderObject.input._touchedHandler(this); + } + */ + + if (this.targetObject !== null) + { + this.targetObject.input._touchedHandler(this); + } + return this; } @@ -361,30 +393,46 @@ module Phaser { // Iterate through the tracked objects // Build our temporary click stack + /* var _highestPriority = 0; + var _highestRenderID = 0; + var _highestRenderObject = null; for (var i = 0; i < this.game.input.totalTrackedObjects; i++) { if (this.game.input.inputObjects[i].input.enabled) { - if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority) + //if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority) + if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID) { - _highestPriority = this.game.input.inputObjects[i].input.priorityID; + _highestRenderID = this.game.input.inputObjects[i].renderOrderID; + _highestRenderObject = this.game.input.inputObjects[i]; } } } - if (this.isDown) + if (_highestRenderObject !== null) { - // Now update all objects with the highest priority ID (can be more than 1) - for (var i = 0; i < this.game.input.totalTrackedObjects; i++) + _highestRenderObject.input._pointerOverHandler(this); + + if (this.isDown && this._stateReset == false) { - if (this.game.input.inputObjects[i].input.priorityID == _highestPriority) - { - this.game.input.inputObjects[i].input._touchedHandler(this); - } + _highestRenderObject.input._touchedHandler(this); } + + // Now update all objects with the highest priority ID (can be more than 1) + //for (var i = 0; i < this.game.input.totalTrackedObjects; i++) + //{ + // if (this.game.input.inputObjects[i].input.priorityID == _highestPriority) + // { + // if (this.game.input.inputObjects[i].input._touchedHandler(this) == false) + // { + // return; + // } + // } + //} } + */ } @@ -425,6 +473,38 @@ module Phaser { this.game.input.circle.y = this.game.input.y; } + if (this.targetObject !== null) + { + if (this.targetObject.input.update(this) == false) + { + this.targetObject = null; + } + } + else + { + // Build our temporary click stack + var _highestRenderID = 0; + var _highestRenderObject: number = -1; + + for (var i = 0; i < this.game.input.totalTrackedObjects; i++) + { + if (this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID) + { + _highestRenderID = this.game.input.inputObjects[i].renderOrderID; + _highestRenderObject = i; + } + } + + //console.log('pointer move', _highestRenderID); + + if (_highestRenderObject !== -1) + { + console.log('setting target'); + this.targetObject = this.game.input.inputObjects[_highestRenderObject]; + this.targetObject.input._pointerOverHandler(this); + } + } + return this; } @@ -448,6 +528,12 @@ module Phaser { */ public stop(event): Pointer { + if (this._stateReset) + { + event.preventDefault(); + return; + } + this.timeUp = this.game.time.now; if (this.game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) @@ -497,7 +583,12 @@ module Phaser { } } - this.draggedObject = null; + if (this.targetObject) + { + this.targetObject.input._releasedHandler(this); + } + + this.targetObject = null; return this; @@ -547,13 +638,19 @@ module Phaser { */ public reset() { - this.active = false; + if (this.isMouse == false) + { + this.active = false; + } + this.identifier = null; this.isDown = false; this.isUp = true; this.totalTouches = 0; this._holdSent = false; this._history.length = 0; + this._stateReset = true; + this.targetObject = null; } diff --git a/Phaser/loader/AnimationLoader.ts b/Phaser/loader/AnimationLoader.ts index 8860799f..aa1a680d 100644 --- a/Phaser/loader/AnimationLoader.ts +++ b/Phaser/loader/AnimationLoader.ts @@ -88,8 +88,7 @@ module Phaser { var data: FrameData = new FrameData(); // By this stage frames is a fully parsed array - var frames = json; - + var frames = json['frames']; var newFrame: Frame; for (var i = 0; i < frames.length; i++) diff --git a/Phaser/loader/Cache.ts b/Phaser/loader/Cache.ts index 3cea89f4..4cd8a1dc 100644 --- a/Phaser/loader/Cache.ts +++ b/Phaser/loader/Cache.ts @@ -89,7 +89,7 @@ module Phaser { * @param data {object} Extra texture atlas data. * @param atlasData {object} Texture atlas frames data. */ - public addTextureAtlas(key: string, url: string, data, atlasData, format) { + public addTextureAtlas(key: string, url: string, data, atlasData, format: number) { this._images[key] = { url: url, data: data, spriteSheet: true }; diff --git a/Phaser/loader/Loader.ts b/Phaser/loader/Loader.ts index a3bb788c..509f9edd 100644 --- a/Phaser/loader/Loader.ts +++ b/Phaser/loader/Loader.ts @@ -434,7 +434,7 @@ module Phaser { var data = JSON.parse(this._xhr.response); var file = this._fileList[key]; - this._game.cache.addTextureAtlas(file.key, file.url, file.data, data['frames'], file.format); + this._game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format); this.nextFile(key, true); diff --git a/Phaser/renderers/CanvasRenderer.ts b/Phaser/renderers/CanvasRenderer.ts index 2fc79a80..241bf1dd 100644 --- a/Phaser/renderers/CanvasRenderer.ts +++ b/Phaser/renderers/CanvasRenderer.ts @@ -99,6 +99,62 @@ module Phaser { } + public renderCircle(camera: Camera, circle: Circle, context, outline?: bool = false, fill?: bool = true, lineColor?: string = 'rgb(0,255,0)', fillColor?: string = 'rgba(0,100,0.0.3)', lineWidth?: number = 1): bool { + + this._count++; + + // Reset our temp vars + this._sx = 0; + this._sy = 0; + this._sw = circle.diameter; + this._sh = circle.diameter; + this._fx = 1; + this._fy = 1; + this._sin = 0; + this._cos = 1; + this._dx = camera.scaledX + circle.x - camera.worldView.x; + this._dy = camera.scaledY + circle.y - camera.worldView.y; + this._dw = circle.diameter; + this._dh = circle.diameter; + + this._sx = Math.round(this._sx); + this._sy = Math.round(this._sy); + this._sw = Math.round(this._sw); + this._sh = Math.round(this._sh); + this._dx = Math.round(this._dx); + this._dy = Math.round(this._dy); + this._dw = Math.round(this._dw); + this._dh = Math.round(this._dh); + + this._game.stage.saveCanvasValues(); + + context.save(); + context.lineWidth = lineWidth; + context.strokeStyle = lineColor; + context.fillStyle = fillColor; + + context.beginPath(); + context.arc(this._dx, this._dy, circle.radius, 0, Math.PI * 2); + context.closePath(); + + if (outline) + { + //context.stroke(); + } + + if (fill) + { + context.fill(); + } + + context.restore(); + + this._game.stage.restoreCanvasValues(); + + return true; + + } + /** * Render this sprite to specific camera. Called by game loop after update(). * @param camera {Camera} Camera this sprite will be rendered to. @@ -111,6 +167,8 @@ module Phaser { return false; } + sprite.renderOrderID = this._count; + this._count++; // Reset our temp vars diff --git a/Phaser/renderers/HeadlessRenderer.ts b/Phaser/renderers/HeadlessRenderer.ts index 86a48b92..1a961ace 100644 --- a/Phaser/renderers/HeadlessRenderer.ts +++ b/Phaser/renderers/HeadlessRenderer.ts @@ -28,6 +28,10 @@ module Phaser { return true; } + public renderCircle(camera: Camera, circle: Circle, context, outline?: bool = true, fill?: bool = true, lineColor?: string = 'rgb(0,255,0)', fillColor?: string = 'rgba(0,100,0.0.3)', lineWidth?: number = 1): bool { + return true; + } + } } \ No newline at end of file diff --git a/Phaser/renderers/IRenderer.ts b/Phaser/renderers/IRenderer.ts index af0ab3bb..dc82fa4e 100644 --- a/Phaser/renderers/IRenderer.ts +++ b/Phaser/renderers/IRenderer.ts @@ -9,6 +9,8 @@ module Phaser { renderSprite(camera: Camera, sprite: Sprite): bool; renderScrollZone(camera: Camera, sprite: ScrollZone): bool; + renderCircle(camera: Camera, circle: Circle, context, outline?: bool, fill?: bool, lineColor?: string, fillColor?: string, lineWidth?: number); + } } \ No newline at end of file diff --git a/README.md b/README.md index c6b82ae0..a33e99f8 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,10 @@ TODO: * Stage CSS3 transforms!!! Color tints, sepia, greyscale, all of those cool things :) * Cameras should have option to be input disabled + Pointers should check which camera they are over before doing Sprite selection * Can Cameras be positioned within the world? +* Added JSON Texture Atlas object support. +* Bug in AnimationManager set frame/frameName - the width/height are trimmed and wrong +* RenderOrderID won't work across cameras - but then neither do Pointers yet anyway + V1.0.0 @@ -76,7 +80,8 @@ V1.0.0 * Added Input drag, bounds, sprite bounds and snapping support. * Added the new ColorUtils class full of lots of handy color manipulation functions. * Fixed issue in Camera.inCamera check where it wouldn't take into consideration the Sprites scrollFactor. - +* Fixed issue with JSON Atlas loader incorrectly parsing the frames array. +* Fixed bug in FrameData.getFrameByName where the first frame of the array would always be skipped. diff --git a/Tests/phaser.js b/Tests/phaser.js index 7c7d9a1f..49912f67 100644 --- a/Tests/phaser.js +++ b/Tests/phaser.js @@ -1394,6 +1394,37 @@ var Phaser; this.game.stage.context.restore(); } }; + Group.prototype.directRender = /** + * Calls render on all members of this Group regardless of their visible status and also ignores the camera blacklist. + * Use this when the Group objects render to hidden canvases for example. + */ + function (camera) { + if(this.globalCompositeOperation) { + this.game.stage.context.save(); + this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation; + } + if(this.alpha > 0) { + this._prevAlpha = this.game.stage.context.globalAlpha; + this.game.stage.context.globalAlpha = this.alpha; + } + this._i = 0; + while(this._i < this.length) { + this._member = this.members[this._i++]; + if(this._member != null && this._member.exists) { + if(this._member.type == Phaser.Types.GROUP) { + this._member.directRender(camera); + } else { + this.game.renderer.renderGameObject(this._member); + } + } + } + if(this.alpha > 0) { + this.game.stage.context.globalAlpha = this._prevAlpha; + } + if(this.globalCompositeOperation) { + this.game.stage.context.restore(); + } + }; Object.defineProperty(Group.prototype, "maxSize", { get: /** * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow. @@ -2630,7 +2661,7 @@ var Phaser; function (key) { var data = JSON.parse(this._xhr.response); var file = this._fileList[key]; - this._game.cache.addTextureAtlas(file.key, file.url, file.data, data['frames'], file.format); + this._game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format); this.nextFile(key, true); }; Loader.prototype.dataLoadError = /** @@ -4121,7 +4152,7 @@ var Phaser; // Let's create some frames then var data = new Phaser.FrameData(); // By this stage frames is a fully parsed array - var frames = json; + var frames = json['frames']; var newFrame; for(var i = 0; i < frames.length; i++) { newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename)); @@ -4326,6 +4357,7 @@ var Phaser; * Either cw or ccw, rotation is always 90 degrees. */ this.rotationDirection = 'cw'; + console.log('Creating Frame', name, 'x', x, 'y', y, 'width', width, 'height', height); this.x = x; this.y = y; this.width = width; @@ -4345,10 +4377,10 @@ var Phaser; * @param trimmed {boolean} Whether this frame trimmed or not. * @param actualWidth {number} Actual width of this frame. * @param actualHeight {number} Actual height of this frame. - * @param destX {number} Destiny x position. - * @param destY {number} Destiny y position. - * @param destWidth {number} Destiny draw width. - * @param destHeight {number} Destiny draw height. + * @param destX {number} Destination x position. + * @param destY {number} Destination y position. + * @param destWidth {number} Destination draw width. + * @param destHeight {number} Destination draw height. */ function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) { this.trimmed = trimmed; @@ -4416,7 +4448,7 @@ var Phaser; * @return {Frame} The frame you want. */ function (name) { - if(this._frameNames[name] >= 0) { + if(this._frameNames[name] !== '') { return this._frames[this._frameNames[name]]; } return null; @@ -4427,7 +4459,7 @@ var Phaser; * @return {boolean} True if frame with given name found, otherwise return false. */ function (name) { - if(this._frameNames[name] >= 0) { + if(this._frameNames[name]) { return true; } return false; @@ -4460,7 +4492,7 @@ var Phaser; return output; }; FrameData.prototype.getFrameIndexesByName = /** - * Get all names of frames by giving their indexes. + * Get the frame indexes by giving the frame names. * @param [output] {number[]} result will be added into this array. * @return {number[]} Names of specific frames in an array. */ @@ -4675,6 +4707,8 @@ var Phaser; this.currentFrame = this._frameData.getFrameByName(value); this._parent.frameBounds.width = this.currentFrame.width; this._parent.frameBounds.height = this.currentFrame.height; + //this._parent.frameBounds.width = this.currentFrame.sourceSizeW; + //this._parent.frameBounds.height = this.currentFrame.sourceSizeH; this._frameIndex = this.currentFrame.index; } }, @@ -6066,6 +6100,7 @@ var Phaser; * @default null */ this.boundsSprite = null; + this.consumePointerEvent = false; this.game = parent.game; this._sprite = parent; this.enabled = false; @@ -6202,6 +6237,26 @@ var Phaser; } return this._sprite; }; + Input.prototype.reset = function () { + this.enabled = false; + for(var i = 0; i < 10; i++) { + this._pointerData[i] = { + id: i, + x: 0, + y: 0, + isDown: false, + isUp: false, + isOver: false, + isOut: false, + timeOver: 0, + timeOut: 0, + timeDown: 0, + timeUp: 0, + downDuration: 0, + isDragged: false + }; + } + }; Input.prototype.stop = function () { // Turning off if(this.enabled == false) { @@ -6216,7 +6271,7 @@ var Phaser; * Update */ function (pointer) { - if(this.enabled == false) { + if(this.enabled == false || this._sprite.visible == false) { return false; } if(this.draggable && this._draggedPointerID == pointer.id) { @@ -6251,6 +6306,7 @@ var Phaser; }; Input.prototype._touchedHandler = function (pointer) { if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) { + console.log('touchDown on', this._sprite.texture.cacheKey, this._sprite.frameBounds.width, this._sprite.frameBounds.height); this._pointerData[pointer.id].isDown = true; this._pointerData[pointer.id].isUp = false; this._pointerData[pointer.id].timeDown = this.game.time.now; @@ -6260,6 +6316,8 @@ var Phaser; this.startDrag(pointer); } } + // Consume the event? + return this.consumePointerEvent; }; Input.prototype._releasedHandler = function (pointer) { // If was previously touched by this Pointer, check if still is @@ -7197,8 +7255,8 @@ var Phaser; function () { this.frameBounds.x = this.x; this.frameBounds.y = this.y; - this.screen.x = this.x - (this.game.camera.worldView.x * this.scrollFactor.x); - this.screen.y = this.y - (this.game.camera.worldView.y * this.scrollFactor.y); + this.screen.x = this.x - (this.game.world.cameras.default.worldView.x * this.scrollFactor.x); + this.screen.y = this.y - (this.game.world.cameras.default.worldView.y * this.scrollFactor.y); if(this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.angle != 0 || this.angleOffset != 0 || this.texture.flippedX || this.texture.flippedY)) { this.modified = true; } @@ -7254,7 +7312,8 @@ var Phaser; * Clean up memory. */ function () { - }; + //this.input.destroy(); + }; Sprite.prototype.kill = /** * Handy for "killing" game objects. * Default behavior is to flag them as nonexistent AND dead. @@ -13787,6 +13846,8 @@ var Phaser; * @private */ this._nextDrop = 0; + // Monitor events outside of a state reset loop + this._stateReset = false; /** * A Vector object containing the initial position when the Pointer was engaged with the screen. * @property positionDown @@ -13973,6 +14034,7 @@ var Phaser; this.game.input.y = this.y * this.game.input.scaleY; this.game.input.onDown.dispatch(this); } + this._stateReset = false; this.totalTouches++; if(this.isMouse == false) { this.game.input.currentPointers++; @@ -14008,11 +14070,13 @@ var Phaser; } } } - if(this.isDown) { + if(this.isDown && this._stateReset == false) { // Now update all objects with the highest priority ID (can be more than 1) for(var i = 0; i < this.game.input.totalTrackedObjects; i++) { if(this.game.input.inputObjects[i].input.priorityID == _highestPriority) { - this.game.input.inputObjects[i].input._touchedHandler(this); + if(this.game.input.inputObjects[i].input._touchedHandler(this) == false) { + return; + } } } } @@ -14062,6 +14126,10 @@ var Phaser; * @param {Any} event */ function (event) { + if(this._stateReset) { + event.preventDefault(); + return; + } this.timeUp = this.game.time.now; if(this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) { this.game.input.onUp.dispatch(this); @@ -14129,13 +14197,16 @@ var Phaser; * @method reset */ function () { - this.active = false; + if(this.isMouse == false) { + this.active = false; + } this.identifier = null; this.isDown = false; this.isUp = true; this.totalTouches = 0; this._holdSent = false; this._history.length = 0; + this._stateReset = true; }; Pointer.prototype.renderDebug = /** * Renders the Pointer.circle object onto the stage in green if down or red if up. @@ -14981,7 +15052,6 @@ var Phaser; this.inputObjects = []; this.totalTrackedObjects = 0; this._game = game; - this._stack = []; this.mousePointer = new Phaser.Pointer(this._game, 0); this.pointer1 = new Phaser.Pointer(this._game, 1); this.pointer2 = new Phaser.Pointer(this._game, 2); @@ -15120,9 +15190,6 @@ var Phaser; this.pointer10.update(); } }; - Input.prototype.addToStack = function (item) { - this._stack.push(item); - }; Input.prototype.reset = /** * Reset all of the Pointers and Input states * @method reset @@ -15131,6 +15198,7 @@ var Phaser; function (hard) { if (typeof hard === "undefined") { hard = false; } this.keyboard.reset(); + this.mousePointer.reset(); this.pointer1.reset(); this.pointer2.reset(); this.pointer3.reset(); @@ -15152,7 +15220,17 @@ var Phaser; this.pointer10.reset(); } this.currentPointers = 0; + for(var i = 0; i < this.totalTrackedObjects; i++) { + this.inputObjects[i].input.reset(); + } + this._game.stage.canvas.style.cursor = "default"; + this.inputObjects.length = 0; + this.totalTrackedObjects = 0; if(hard == true) { + this.onDown.dispose(); + this.onUp.dispose(); + this.onTap.dispose(); + this.onHold.dispose(); this.onDown = new Phaser.Signal(); this.onUp = new Phaser.Signal(); this.onTap = new Phaser.Signal(); @@ -15433,6 +15511,14 @@ var Phaser; HeadlessRenderer.prototype.renderScrollZone = function (camera, scrollZone) { return true; }; + HeadlessRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) { + if (typeof outline === "undefined") { outline = true; } + if (typeof fill === "undefined") { fill = true; } + if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; } + if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; } + if (typeof lineWidth === "undefined") { lineWidth = 1; } + return true; + }; return HeadlessRenderer; })(); Phaser.HeadlessRenderer = HeadlessRenderer; @@ -15498,6 +15584,52 @@ var Phaser; this._dh = sprite.frameBounds.height * sprite.scale.y; return (camera.scaledX + camera.worldView.width > this._dx) && (camera.scaledX < this._dx + this._dw) && (camera.scaledY + camera.worldView.height > this._dy) && (camera.scaledY < this._dy + this._dh); }; + CanvasRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) { + if (typeof outline === "undefined") { outline = false; } + if (typeof fill === "undefined") { fill = true; } + if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; } + if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; } + if (typeof lineWidth === "undefined") { lineWidth = 1; } + this._count++; + // Reset our temp vars + this._sx = 0; + this._sy = 0; + this._sw = circle.diameter; + this._sh = circle.diameter; + this._fx = 1; + this._fy = 1; + this._sin = 0; + this._cos = 1; + this._dx = camera.scaledX + circle.x - camera.worldView.x; + this._dy = camera.scaledY + circle.y - camera.worldView.y; + this._dw = circle.diameter; + this._dh = circle.diameter; + this._sx = Math.round(this._sx); + this._sy = Math.round(this._sy); + this._sw = Math.round(this._sw); + this._sh = Math.round(this._sh); + this._dx = Math.round(this._dx); + this._dy = Math.round(this._dy); + this._dw = Math.round(this._dw); + this._dh = Math.round(this._dh); + this._game.stage.saveCanvasValues(); + context.save(); + context.lineWidth = lineWidth; + context.strokeStyle = lineColor; + context.fillStyle = fillColor; + context.beginPath(); + context.arc(this._dx, this._dy, circle.radius, 0, Math.PI * 2); + context.closePath(); + if(outline) { + //context.stroke(); + } + if(fill) { + context.fill(); + } + context.restore(); + this._game.stage.restoreCanvasValues(); + return true; + }; CanvasRenderer.prototype.renderSprite = /** * Render this sprite to specific camera. Called by game loop after update(). * @param camera {Camera} Camera this sprite will be rendered to. diff --git a/build/phaser.d.ts b/build/phaser.d.ts index 0aa0437a..bcbdc138 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -997,6 +997,11 @@ module Phaser { */ public render(camera: Camera): void; /** + * Calls render on all members of this Group regardless of their visible status and also ignores the camera blacklist. + * Use this when the Group objects render to hidden canvases for example. + */ + public directRender(camera: Camera): void; + /** * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow. */ /** @@ -1659,7 +1664,7 @@ module Phaser { * @param data {object} Extra texture atlas data. * @param atlasData {object} Texture atlas frames data. */ - public addTextureAtlas(key: string, url: string, data, atlasData, format): void; + public addTextureAtlas(key: string, url: string, data, atlasData, format: number): void; /** * Add a new image. * @param key {string} Asset key for the image. @@ -2615,10 +2620,10 @@ module Phaser { * @param trimmed {boolean} Whether this frame trimmed or not. * @param actualWidth {number} Actual width of this frame. * @param actualHeight {number} Actual height of this frame. - * @param destX {number} Destiny x position. - * @param destY {number} Destiny y position. - * @param destWidth {number} Destiny draw width. - * @param destHeight {number} Destiny draw height. + * @param destX {number} Destination x position. + * @param destY {number} Destination y position. + * @param destWidth {number} Destination draw width. + * @param destHeight {number} Destination draw height. */ public setTrim(trimmed: bool, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number): void; } @@ -2682,7 +2687,7 @@ module Phaser { */ public getFrameIndexes(output?: number[]): number[]; /** - * Get all names of frames by giving their indexes. + * Get the frame indexes by giving the frame names. * @param [output] {number[]} result will be added into this array. * @return {number[]} Names of specific frames in an array. */ @@ -3612,12 +3617,14 @@ module Phaser.Components { */ public pointerDragged(pointer?: number): bool; public start(priority?: number, checkBody?: bool, useHandCursor?: bool): Sprite; + public reset(): void; public stop(): void; /** * Update */ public update(pointer: Pointer): bool; - public _touchedHandler(pointer: Pointer): void; + public consumePointerEvent: bool; + public _touchedHandler(pointer: Pointer): bool; public _releasedHandler(pointer: Pointer): void; /** * Updates the Pointer drag on this Sprite. @@ -4113,6 +4120,11 @@ module Phaser { * The Sprite origin is the point around which scale and rotation takes place. */ public origin: Vec2; + /** + * A Point holding the x/y coordinate of this Sprite relative to the screen. It uses the default created world + * camera to calculate its values. If you have changed the default camera (i.e. resized it, deleted it) this value + * will be incorrect and should be ignored. + */ public screen: Point; /** * x value of the object. @@ -7369,6 +7381,7 @@ module Phaser { * @private */ private _nextDrop; + private _stateReset; /** * The Pointer ID (a number between 1 and 10, 0 is reserved for the mouse pointer specifically) * @property id @@ -7991,10 +8004,6 @@ module Phaser { */ private _game; /** - * Temporary click sorting stack - */ - private _stack; - /** * A vector object representing the previous position of the Pointer. * @property vector * @type {Vec2} @@ -8274,7 +8283,6 @@ module Phaser { * @method update **/ public update(): void; - public addToStack(item): void; /** * Reset all of the Pointers and Input states * @method reset @@ -8364,6 +8372,7 @@ module Phaser { renderGameObject(object); renderSprite(camera: Camera, sprite: Sprite): bool; renderScrollZone(camera: Camera, sprite: ScrollZone): bool; + renderCircle(camera: Camera, circle: Circle, context, outline?: bool, fill?: bool, lineColor?: string, fillColor?: string, lineWidth?: number); } } module Phaser { @@ -8377,6 +8386,7 @@ module Phaser { public renderGameObject(object): void; public renderSprite(camera: Camera, sprite: Sprite): bool; public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool; + public renderCircle(camera: Camera, circle: Circle, context, outline?: bool, fill?: bool, lineColor?: string, fillColor?: string, lineWidth?: number): bool; } } module Phaser { @@ -8412,6 +8422,7 @@ module Phaser { * @return {boolean} Return true if bounds of this sprite intersects the given rectangle, otherwise return false. */ public inCamera(camera: Camera, sprite: Sprite): bool; + public renderCircle(camera: Camera, circle: Circle, context, outline?: bool, fill?: bool, lineColor?: string, fillColor?: string, lineWidth?: number): bool; /** * Render this sprite to specific camera. Called by game loop after update(). * @param camera {Camera} Camera this sprite will be rendered to. diff --git a/build/phaser.js b/build/phaser.js index 7c7d9a1f..49912f67 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -1394,6 +1394,37 @@ var Phaser; this.game.stage.context.restore(); } }; + Group.prototype.directRender = /** + * Calls render on all members of this Group regardless of their visible status and also ignores the camera blacklist. + * Use this when the Group objects render to hidden canvases for example. + */ + function (camera) { + if(this.globalCompositeOperation) { + this.game.stage.context.save(); + this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation; + } + if(this.alpha > 0) { + this._prevAlpha = this.game.stage.context.globalAlpha; + this.game.stage.context.globalAlpha = this.alpha; + } + this._i = 0; + while(this._i < this.length) { + this._member = this.members[this._i++]; + if(this._member != null && this._member.exists) { + if(this._member.type == Phaser.Types.GROUP) { + this._member.directRender(camera); + } else { + this.game.renderer.renderGameObject(this._member); + } + } + } + if(this.alpha > 0) { + this.game.stage.context.globalAlpha = this._prevAlpha; + } + if(this.globalCompositeOperation) { + this.game.stage.context.restore(); + } + }; Object.defineProperty(Group.prototype, "maxSize", { get: /** * The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow. @@ -2630,7 +2661,7 @@ var Phaser; function (key) { var data = JSON.parse(this._xhr.response); var file = this._fileList[key]; - this._game.cache.addTextureAtlas(file.key, file.url, file.data, data['frames'], file.format); + this._game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format); this.nextFile(key, true); }; Loader.prototype.dataLoadError = /** @@ -4121,7 +4152,7 @@ var Phaser; // Let's create some frames then var data = new Phaser.FrameData(); // By this stage frames is a fully parsed array - var frames = json; + var frames = json['frames']; var newFrame; for(var i = 0; i < frames.length; i++) { newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename)); @@ -4326,6 +4357,7 @@ var Phaser; * Either cw or ccw, rotation is always 90 degrees. */ this.rotationDirection = 'cw'; + console.log('Creating Frame', name, 'x', x, 'y', y, 'width', width, 'height', height); this.x = x; this.y = y; this.width = width; @@ -4345,10 +4377,10 @@ var Phaser; * @param trimmed {boolean} Whether this frame trimmed or not. * @param actualWidth {number} Actual width of this frame. * @param actualHeight {number} Actual height of this frame. - * @param destX {number} Destiny x position. - * @param destY {number} Destiny y position. - * @param destWidth {number} Destiny draw width. - * @param destHeight {number} Destiny draw height. + * @param destX {number} Destination x position. + * @param destY {number} Destination y position. + * @param destWidth {number} Destination draw width. + * @param destHeight {number} Destination draw height. */ function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) { this.trimmed = trimmed; @@ -4416,7 +4448,7 @@ var Phaser; * @return {Frame} The frame you want. */ function (name) { - if(this._frameNames[name] >= 0) { + if(this._frameNames[name] !== '') { return this._frames[this._frameNames[name]]; } return null; @@ -4427,7 +4459,7 @@ var Phaser; * @return {boolean} True if frame with given name found, otherwise return false. */ function (name) { - if(this._frameNames[name] >= 0) { + if(this._frameNames[name]) { return true; } return false; @@ -4460,7 +4492,7 @@ var Phaser; return output; }; FrameData.prototype.getFrameIndexesByName = /** - * Get all names of frames by giving their indexes. + * Get the frame indexes by giving the frame names. * @param [output] {number[]} result will be added into this array. * @return {number[]} Names of specific frames in an array. */ @@ -4675,6 +4707,8 @@ var Phaser; this.currentFrame = this._frameData.getFrameByName(value); this._parent.frameBounds.width = this.currentFrame.width; this._parent.frameBounds.height = this.currentFrame.height; + //this._parent.frameBounds.width = this.currentFrame.sourceSizeW; + //this._parent.frameBounds.height = this.currentFrame.sourceSizeH; this._frameIndex = this.currentFrame.index; } }, @@ -6066,6 +6100,7 @@ var Phaser; * @default null */ this.boundsSprite = null; + this.consumePointerEvent = false; this.game = parent.game; this._sprite = parent; this.enabled = false; @@ -6202,6 +6237,26 @@ var Phaser; } return this._sprite; }; + Input.prototype.reset = function () { + this.enabled = false; + for(var i = 0; i < 10; i++) { + this._pointerData[i] = { + id: i, + x: 0, + y: 0, + isDown: false, + isUp: false, + isOver: false, + isOut: false, + timeOver: 0, + timeOut: 0, + timeDown: 0, + timeUp: 0, + downDuration: 0, + isDragged: false + }; + } + }; Input.prototype.stop = function () { // Turning off if(this.enabled == false) { @@ -6216,7 +6271,7 @@ var Phaser; * Update */ function (pointer) { - if(this.enabled == false) { + if(this.enabled == false || this._sprite.visible == false) { return false; } if(this.draggable && this._draggedPointerID == pointer.id) { @@ -6251,6 +6306,7 @@ var Phaser; }; Input.prototype._touchedHandler = function (pointer) { if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) { + console.log('touchDown on', this._sprite.texture.cacheKey, this._sprite.frameBounds.width, this._sprite.frameBounds.height); this._pointerData[pointer.id].isDown = true; this._pointerData[pointer.id].isUp = false; this._pointerData[pointer.id].timeDown = this.game.time.now; @@ -6260,6 +6316,8 @@ var Phaser; this.startDrag(pointer); } } + // Consume the event? + return this.consumePointerEvent; }; Input.prototype._releasedHandler = function (pointer) { // If was previously touched by this Pointer, check if still is @@ -7197,8 +7255,8 @@ var Phaser; function () { this.frameBounds.x = this.x; this.frameBounds.y = this.y; - this.screen.x = this.x - (this.game.camera.worldView.x * this.scrollFactor.x); - this.screen.y = this.y - (this.game.camera.worldView.y * this.scrollFactor.y); + this.screen.x = this.x - (this.game.world.cameras.default.worldView.x * this.scrollFactor.x); + this.screen.y = this.y - (this.game.world.cameras.default.worldView.y * this.scrollFactor.y); if(this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.angle != 0 || this.angleOffset != 0 || this.texture.flippedX || this.texture.flippedY)) { this.modified = true; } @@ -7254,7 +7312,8 @@ var Phaser; * Clean up memory. */ function () { - }; + //this.input.destroy(); + }; Sprite.prototype.kill = /** * Handy for "killing" game objects. * Default behavior is to flag them as nonexistent AND dead. @@ -13787,6 +13846,8 @@ var Phaser; * @private */ this._nextDrop = 0; + // Monitor events outside of a state reset loop + this._stateReset = false; /** * A Vector object containing the initial position when the Pointer was engaged with the screen. * @property positionDown @@ -13973,6 +14034,7 @@ var Phaser; this.game.input.y = this.y * this.game.input.scaleY; this.game.input.onDown.dispatch(this); } + this._stateReset = false; this.totalTouches++; if(this.isMouse == false) { this.game.input.currentPointers++; @@ -14008,11 +14070,13 @@ var Phaser; } } } - if(this.isDown) { + if(this.isDown && this._stateReset == false) { // Now update all objects with the highest priority ID (can be more than 1) for(var i = 0; i < this.game.input.totalTrackedObjects; i++) { if(this.game.input.inputObjects[i].input.priorityID == _highestPriority) { - this.game.input.inputObjects[i].input._touchedHandler(this); + if(this.game.input.inputObjects[i].input._touchedHandler(this) == false) { + return; + } } } } @@ -14062,6 +14126,10 @@ var Phaser; * @param {Any} event */ function (event) { + if(this._stateReset) { + event.preventDefault(); + return; + } this.timeUp = this.game.time.now; if(this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) { this.game.input.onUp.dispatch(this); @@ -14129,13 +14197,16 @@ var Phaser; * @method reset */ function () { - this.active = false; + if(this.isMouse == false) { + this.active = false; + } this.identifier = null; this.isDown = false; this.isUp = true; this.totalTouches = 0; this._holdSent = false; this._history.length = 0; + this._stateReset = true; }; Pointer.prototype.renderDebug = /** * Renders the Pointer.circle object onto the stage in green if down or red if up. @@ -14981,7 +15052,6 @@ var Phaser; this.inputObjects = []; this.totalTrackedObjects = 0; this._game = game; - this._stack = []; this.mousePointer = new Phaser.Pointer(this._game, 0); this.pointer1 = new Phaser.Pointer(this._game, 1); this.pointer2 = new Phaser.Pointer(this._game, 2); @@ -15120,9 +15190,6 @@ var Phaser; this.pointer10.update(); } }; - Input.prototype.addToStack = function (item) { - this._stack.push(item); - }; Input.prototype.reset = /** * Reset all of the Pointers and Input states * @method reset @@ -15131,6 +15198,7 @@ var Phaser; function (hard) { if (typeof hard === "undefined") { hard = false; } this.keyboard.reset(); + this.mousePointer.reset(); this.pointer1.reset(); this.pointer2.reset(); this.pointer3.reset(); @@ -15152,7 +15220,17 @@ var Phaser; this.pointer10.reset(); } this.currentPointers = 0; + for(var i = 0; i < this.totalTrackedObjects; i++) { + this.inputObjects[i].input.reset(); + } + this._game.stage.canvas.style.cursor = "default"; + this.inputObjects.length = 0; + this.totalTrackedObjects = 0; if(hard == true) { + this.onDown.dispose(); + this.onUp.dispose(); + this.onTap.dispose(); + this.onHold.dispose(); this.onDown = new Phaser.Signal(); this.onUp = new Phaser.Signal(); this.onTap = new Phaser.Signal(); @@ -15433,6 +15511,14 @@ var Phaser; HeadlessRenderer.prototype.renderScrollZone = function (camera, scrollZone) { return true; }; + HeadlessRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) { + if (typeof outline === "undefined") { outline = true; } + if (typeof fill === "undefined") { fill = true; } + if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; } + if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; } + if (typeof lineWidth === "undefined") { lineWidth = 1; } + return true; + }; return HeadlessRenderer; })(); Phaser.HeadlessRenderer = HeadlessRenderer; @@ -15498,6 +15584,52 @@ var Phaser; this._dh = sprite.frameBounds.height * sprite.scale.y; return (camera.scaledX + camera.worldView.width > this._dx) && (camera.scaledX < this._dx + this._dw) && (camera.scaledY + camera.worldView.height > this._dy) && (camera.scaledY < this._dy + this._dh); }; + CanvasRenderer.prototype.renderCircle = function (camera, circle, context, outline, fill, lineColor, fillColor, lineWidth) { + if (typeof outline === "undefined") { outline = false; } + if (typeof fill === "undefined") { fill = true; } + if (typeof lineColor === "undefined") { lineColor = 'rgb(0,255,0)'; } + if (typeof fillColor === "undefined") { fillColor = 'rgba(0,100,0.0.3)'; } + if (typeof lineWidth === "undefined") { lineWidth = 1; } + this._count++; + // Reset our temp vars + this._sx = 0; + this._sy = 0; + this._sw = circle.diameter; + this._sh = circle.diameter; + this._fx = 1; + this._fy = 1; + this._sin = 0; + this._cos = 1; + this._dx = camera.scaledX + circle.x - camera.worldView.x; + this._dy = camera.scaledY + circle.y - camera.worldView.y; + this._dw = circle.diameter; + this._dh = circle.diameter; + this._sx = Math.round(this._sx); + this._sy = Math.round(this._sy); + this._sw = Math.round(this._sw); + this._sh = Math.round(this._sh); + this._dx = Math.round(this._dx); + this._dy = Math.round(this._dy); + this._dw = Math.round(this._dw); + this._dh = Math.round(this._dh); + this._game.stage.saveCanvasValues(); + context.save(); + context.lineWidth = lineWidth; + context.strokeStyle = lineColor; + context.fillStyle = fillColor; + context.beginPath(); + context.arc(this._dx, this._dy, circle.radius, 0, Math.PI * 2); + context.closePath(); + if(outline) { + //context.stroke(); + } + if(fill) { + context.fill(); + } + context.restore(); + this._game.stage.restoreCanvasValues(); + return true; + }; CanvasRenderer.prototype.renderSprite = /** * Render this sprite to specific camera. Called by game loop after update(). * @param camera {Camera} Camera this sprite will be rendered to.