From 4f2c26df77b13f0e92a4223f5d1841464064e7b1 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 29 Jul 2013 00:43:10 +0100 Subject: [PATCH] Fixed issue with Pointer speed not resetting and moved some more render methods to the Debug class. --- Phaser/components/sprite/Input.ts | 4 +- Phaser/gameobjects/GameObjectFactory.ts | 12 ++++- Phaser/gameobjects/Sprite.ts | 12 +++++ Phaser/input/Input.ts | 13 +++-- Phaser/input/Pointer.ts | 2 + Phaser/utils/DebugUtils.ts | 63 +++++++++++++++---------- README.md | 8 ++-- 7 files changed, 80 insertions(+), 34 deletions(-) diff --git a/Phaser/components/sprite/Input.ts b/Phaser/components/sprite/Input.ts index 0816a341..fb413d05 100644 --- a/Phaser/components/sprite/Input.ts +++ b/Phaser/components/sprite/Input.ts @@ -392,7 +392,7 @@ module Phaser.Components.Sprite { if (this.bringToTop) { - this._parent.group.bringToTop(this._parent); + this._parent.bringToTop(); } } @@ -618,7 +618,7 @@ module Phaser.Components.Sprite { if (this.bringToTop) { - this._parent.group.bringToTop(this._parent); + this._parent.bringToTop(); } this._parent.events.onDragStart.dispatch(this._parent, pointer); diff --git a/Phaser/gameobjects/GameObjectFactory.ts b/Phaser/gameobjects/GameObjectFactory.ts index 78e981a3..294bf2a1 100644 --- a/Phaser/gameobjects/GameObjectFactory.ts +++ b/Phaser/gameobjects/GameObjectFactory.ts @@ -134,7 +134,6 @@ module Phaser { return this._world.group.add(new Group(this._game, maxSize)); } - /** * Create a new Particle. * @@ -207,6 +206,17 @@ module Phaser { return this._world.group.add(sprite); } + /** + * Add an existing Group to the current world. + * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break. + * + * @param group The Group to add to the Game World + * @return {Phaser.Group} The Group object + */ + public existingGroup(group: Group): Group { + return this._world.group.add(group); + } + /** * Add an existing Button to the current world. * Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break. diff --git a/Phaser/gameobjects/Sprite.ts b/Phaser/gameobjects/Sprite.ts index aa1ed7eb..f3d2de24 100644 --- a/Phaser/gameobjects/Sprite.ts +++ b/Phaser/gameobjects/Sprite.ts @@ -237,6 +237,18 @@ module Phaser { } + /** + * Brings this Sprite to the top of its current Group, if set. + */ + public bringToTop() { + + if (this.group) + { + this.group.bringToTop(this); + } + + } + /** * The scale of the Sprite. A value of 1 is original scale. 0.5 is half size. 2 is double the size. * This is a reference to Sprite.transform.scale diff --git a/Phaser/input/Input.ts b/Phaser/input/Input.ts index b427341c..0bb5164f 100644 --- a/Phaser/input/Input.ts +++ b/Phaser/input/Input.ts @@ -377,6 +377,10 @@ module Phaser { **/ public activePointer: Pointer = null; + public inputObjects = []; + + public totalTrackedObjects: number = 0; + /** * The X coordinate of the most recently active pointer. * This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values. @@ -469,9 +473,6 @@ module Phaser { } - public inputObjects = []; - public totalTrackedObjects: number = 0; - /** * Adds a new game object to be tracked by the Input Manager. Called by the Sprite.Input component, should not usually be called directly. * @method addGameObject @@ -536,7 +537,6 @@ module Phaser { if (this.pointer9) { this.pointer9.update(); } if (this.pointer10) { this.pointer10.update(); } - } /** @@ -591,6 +591,11 @@ module Phaser { } + public resetSpeed(x: number, y: number) { + this._oldPosition.setTo(x, y); + this.speed.setTo(0, 0); + } + /** * Get the total number of inactive Pointers * @method totalInactivePointers diff --git a/Phaser/input/Pointer.ts b/Phaser/input/Pointer.ts index 53add492..fb7f93be 100644 --- a/Phaser/input/Pointer.ts +++ b/Phaser/input/Pointer.ts @@ -337,7 +337,9 @@ module Phaser { //this.game.input.y = this.y * this.game.input.scale.y; this.game.input.x = this.x; this.game.input.y = this.y; + this.game.input.position.setTo(this.x, this.y); this.game.input.onDown.dispatch(this); + this.game.input.resetSpeed(this.x, this.y); } this._stateReset = false; diff --git a/Phaser/utils/DebugUtils.ts b/Phaser/utils/DebugUtils.ts index 1d97aa99..add9178b 100644 --- a/Phaser/utils/DebugUtils.ts +++ b/Phaser/utils/DebugUtils.ts @@ -63,12 +63,12 @@ module Phaser { DebugUtils.context.fillText('Vert 3 x: ' + (body.shapes[0].tverts[2].x * 50) + ' y: ' + (body.shapes[0].tverts[2].y * 50), x, y + 84); DebugUtils.context.fillText('Vert 4 x: ' + (body.shapes[0].tverts[3].x * 50) + ' y: ' + (body.shapes[0].tverts[3].y * 50), x, y + 98); -/* - DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56); - DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70); - DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84); - DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98); -*/ + /* + DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56); + DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70); + DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84); + DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98); + */ } @@ -104,6 +104,20 @@ module Phaser { } + /** + * Render text + * @param x {number} X position of the debug info to be rendered. + * @param y {number} Y position of the debug info to be rendered. + * @param [color] {number} color of the debug info to be rendered. (format is css color string) + */ + static renderText(text: string, x: number, y: number, color?: string = 'rgb(255,255,255)') { + + DebugUtils.context.font = '16px Courier'; + DebugUtils.context.fillStyle = color; + DebugUtils.context.fillText(text, x, y); + + } + static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') { for (var s = 0; s < body.shapesLength; s++) @@ -114,35 +128,36 @@ module Phaser { { var verts = body.shapes[s].tverts; -// DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y); + // DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y); DebugUtils.context.moveTo(verts[0].x * 50, verts[0].y * 50); - for (var i = 1; i < verts.length; i++) { -// DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y); + for (var i = 1; i < verts.length; i++) + { + // DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y); DebugUtils.context.lineTo(verts[i].x * 50, verts[i].y * 50); - } + } -// DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y); + // DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y); DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50); } else if (body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_CIRCLE) - { - var circle = body.shapes[s]; - DebugUtils.context.arc(circle.tc.x * 50, circle.tc.y * 50, circle.radius * 50, 0, Math.PI * 2, false); + { + var circle = body.shapes[s]; + DebugUtils.context.arc(circle.tc.x * 50, circle.tc.y * 50, circle.radius * 50, 0, Math.PI * 2, false); } - DebugUtils.context.closePath(); + DebugUtils.context.closePath(); - if (body.isAwake) - { - DebugUtils.context.fillStyle = fillStyle; - } - else - { - DebugUtils.context.fillStyle = sleepStyle; - } + if (body.isAwake) + { + DebugUtils.context.fillStyle = fillStyle; + } + else + { + DebugUtils.context.fillStyle = sleepStyle; + } - DebugUtils.context.fill(); + DebugUtils.context.fill(); } diff --git a/README.md b/README.md index cf554a5a..72ae897e 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,9 @@ TODO: * Ability to layer another DOM object and have it controlled by the game somehow. Can then do stacked canvas effects. * Stage lost to mute * When game is paused Pointer shouldn't process targetObjects / change cursor - - +* Need to limit touch priority of items in groups? +* Bring to Top doesn't seem to respect the group they are in +* Add crop support V1.0.0 @@ -158,7 +159,8 @@ V1.0.0 * Dropped the StageScaleMode.setScreenSize iterations count from 40 down to 10 and document min body height to 2000px. * Added Phaser.Net for browser and network specific functions, currently includes query string parsing and updating methods. * Added a new CSS3 Filters component. Apply blur, grayscale, sepia, brightness, contrast, hue rotation, invert, opacity and saturate filters to the games stage. -* Fixed the CircleUtils.contains and containsPoint methods +* Fixed the CircleUtils.contains and containsPoint methods. +* Fixed issue with Input.speed values being too high on touch events.