diff --git a/Phaser/components/sprite/Texture.ts b/Phaser/components/sprite/Texture.ts index 551839b6..a9c9da21 100644 --- a/Phaser/components/sprite/Texture.ts +++ b/Phaser/components/sprite/Texture.ts @@ -143,7 +143,7 @@ module Phaser.Components { * @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean * @return {Sprite} Sprite instance itself. */ - public loadImage(key: string, clearAnimations: bool = true) { + public loadImage(key: string, clearAnimations?: bool = true, updateBody?: bool = true) { if (clearAnimations && this._sprite.animations.frameData !== null) { @@ -163,6 +163,12 @@ module Phaser.Components { this._sprite.frameBounds.width = this.width; this._sprite.frameBounds.height = this.height; } + + if (updateBody) + { + this._sprite.body.bounds.width = this.width; + this._sprite.body.bounds.height = this.height; + } } } diff --git a/Phaser/core/Group.ts b/Phaser/core/Group.ts index 7ef7f86a..58576798 100644 --- a/Phaser/core/Group.ts +++ b/Phaser/core/Group.ts @@ -201,7 +201,18 @@ module Phaser { if (this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) { - this._member.render.call(renderer, camera, this._member); + //this._member.render.call(renderer, camera, this._member); + // call = context first, then parameters + if (this._member.type == Types.GROUP) + { + //console.log('group rend'); + this._member.render.call(this._member, renderer, camera, this._member); + //this._member.render.call(this, renderer, camera, this._member); + } + else + { + this._member.render.call(renderer, camera, this._member); + } } } diff --git a/Phaser/gameobjects/Emitter.ts b/Phaser/gameobjects/Emitter.ts index 6e4a3d3f..0a7c5fe3 100644 --- a/Phaser/gameobjects/Emitter.ts +++ b/Phaser/gameobjects/Emitter.ts @@ -46,6 +46,10 @@ module Phaser { this._explode = true; this.on = false; + this.exists = true; + this.active = true; + this.visible = true; + } /** @@ -73,6 +77,11 @@ module Phaser { */ public alive: bool; + /** + * + */ + public active: bool; + /** * The minimum possible velocity of a particle. * The default value is (-100,-100). @@ -217,29 +226,14 @@ module Phaser { { /* randomFrame = this.game.math.random()*totalFrames; - if(BakedRotations > 0) - particle.loadRotatedGraphic(Graphics,BakedRotations,randomFrame); - else - { - particle.loadGraphic(Graphics,true); - particle.frame = randomFrame; - } */ } else { - /* - if (BakedRotations > 0) - particle.loadRotatedGraphic(Graphics,BakedRotations); - else - particle.loadGraphic(Graphics); - */ - if (graphics) { particle.texture.loadImage(graphics); } - } if (collide > 0) @@ -255,6 +249,8 @@ module Phaser { } particle.exists = false; + // Center the origin for rotation assistance + particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight); this.add(particle); @@ -264,6 +260,9 @@ module Phaser { return this; } + public preUpdate() { } + public postUpdate() { } + /** * Called automatically by the game loop, decides when to launch particles and when to "die". */ diff --git a/Phaser/gameobjects/Particle.ts b/Phaser/gameobjects/Particle.ts index 341c7e79..ffbc074d 100644 --- a/Phaser/gameobjects/Particle.ts +++ b/Phaser/gameobjects/Particle.ts @@ -20,6 +20,7 @@ module Phaser { super(game); + this.body.type = Types.BODY_DYNAMIC; this.lifespan = 0; this.friction = 500; @@ -45,7 +46,7 @@ module Phaser { */ public update() { - //lifespan behavior + // Lifespan behavior if (this.lifespan <= 0) { return; diff --git a/Phaser/math/QuadTree.ts b/Phaser/math/QuadTree.ts index c4d0b843..1675a98c 100644 --- a/Phaser/math/QuadTree.ts +++ b/Phaser/math/QuadTree.ts @@ -23,10 +23,12 @@ module Phaser { * @param {Number} height Desired height of this node. * @param {Number} parent The parent branch or node. Pass null to create a root. */ - constructor(x: number, y: number, width: number, height: number, parent: QuadTree = null) { + constructor(manager: Phaser.Physics.PhysicsManager, x: number, y: number, width: number, height: number, parent: QuadTree = null) { super(x, y, width, height); + QuadTree.physics = manager; + this._headA = this._tailA = new Phaser.LinkedList(); this._headB = this._tailB = new Phaser.LinkedList(); @@ -102,6 +104,8 @@ module Phaser { private _overlapProcessed: bool; private _checkObject; + public static physics: Phaser.Physics.PhysicsManager; + /** * Flag for specifying that you want to add an object to the A list. */ @@ -392,7 +396,7 @@ module Phaser { { if (this._northWestTree == null) { - this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northWestTree.addObject(); @@ -403,7 +407,7 @@ module Phaser { { if (this._southWestTree == null) { - this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southWestTree.addObject(); @@ -417,7 +421,7 @@ module Phaser { { if (this._northEastTree == null) { - this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northEastTree.addObject(); @@ -428,7 +432,7 @@ module Phaser { { if (this._southEastTree == null) { - this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southEastTree.addObject(); @@ -441,7 +445,7 @@ module Phaser { { if (this._northWestTree == null) { - this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northWestTree.addObject(); @@ -451,7 +455,7 @@ module Phaser { { if (this._northEastTree == null) { - this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northEastTree.addObject(); @@ -461,7 +465,7 @@ module Phaser { { if (this._southEastTree == null) { - this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southEastTree.addObject(); @@ -471,7 +475,7 @@ module Phaser { { if (this._southWestTree == null) { - this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southWestTree.addObject(); @@ -621,7 +625,8 @@ module Phaser { continue; } - if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) + //if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) + if (QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body)) { //Execute callback functions if they exist if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject)) diff --git a/Phaser/physics/PhysicsManager.ts b/Phaser/physics/PhysicsManager.ts index 3f6ccd15..02ca1b5b 100644 --- a/Phaser/physics/PhysicsManager.ts +++ b/Phaser/physics/PhysicsManager.ts @@ -139,7 +139,7 @@ module Phaser.Physics { return; } - this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2; + this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2; body.angularVelocity += this._velocityDelta; body.angle += body.angularVelocity * this.game.time.elapsed; body.angularVelocity += this._velocityDelta; @@ -225,19 +225,8 @@ module Phaser.Physics { } - private checkHullIntersection(body1: Body, body2:Body): bool { - + public checkHullIntersection(body1: Body, body2:Body): bool { return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight)); - - //if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight)) - //{ - // return true; - //} - //else - //{ - // return false; - //} - } /** @@ -753,7 +742,7 @@ module Phaser.Physics { QuadTree.divisions = this.worldDivisions; - this._quadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); + this._quadTree = new QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); this._quadTree.load(object1, object2, notifyCallback, processCallback, context); diff --git a/Phaser/utils/SpriteUtils.ts b/Phaser/utils/SpriteUtils.ts index 678bd113..c9237efb 100644 --- a/Phaser/utils/SpriteUtils.ts +++ b/Phaser/utils/SpriteUtils.ts @@ -278,6 +278,8 @@ module Phaser { sprite.y = y; sprite.body.velocity.x = 0; sprite.body.velocity.y = 0; + sprite.body.position.x = x; + sprite.body.position.y = y; } diff --git a/README.md b/README.md index 8b359d1f..7409c5b0 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ TODO: * Copy the setTransform from Sprite to Camera * Move Camera.scroll.x to just Camera.x/y * Apply Sprite scaling to Body.bounds +* When you modify the sprite x/y directly the body position doesn't update, which leads to weird results. Need to work out who controls who. + V1.0.0 diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 3868a21b..fe6fc110 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -66,6 +66,22 @@ scrollfactor 2.ts + + + graphic emitter.ts + + + + multiple streams.ts + + + + sprite emitter.ts + + + + when particles collide.ts + aabb 1.ts @@ -158,8 +174,6 @@ boot screen.ts - - - + \ No newline at end of file diff --git a/Tests/particles/graphic emitter.js b/Tests/particles/graphic emitter.js new file mode 100644 index 00000000..b86f9bd3 --- /dev/null +++ b/Tests/particles/graphic emitter.js @@ -0,0 +1,14 @@ +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create); + var emitter; + function init() { + game.loader.addImageFile('jet', 'assets/sprites/jets.png'); + game.loader.load(); + } + function create() { + emitter = game.add.emitter(game.stage.centerX, game.stage.centerY); + emitter.makeParticles('jet', 50, false, 0); + emitter.start(false, 10, 0.1); + } +})(); diff --git a/Tests/particles/graphic emitter.ts b/Tests/particles/graphic emitter.ts new file mode 100644 index 00000000..705e0dfd --- /dev/null +++ b/Tests/particles/graphic emitter.ts @@ -0,0 +1,25 @@ +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create); + + var emitter: Phaser.Emitter; + + function init() { + + game.loader.addImageFile('jet', 'assets/sprites/jets.png'); + + game.loader.load(); + + } + + function create() { + + emitter = game.add.emitter(game.stage.centerX, game.stage.centerY); + emitter.makeParticles('jet', 50, false, 0); + emitter.start(false, 10, 0.1); + + } + +})(); diff --git a/Tests/particles/multiple streams.js b/Tests/particles/multiple streams.js new file mode 100644 index 00000000..f073067a --- /dev/null +++ b/Tests/particles/multiple streams.js @@ -0,0 +1,49 @@ +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + var emitter1; + var emitter2; + var emitter3; + var emitter4; + var emitter5; + var emitter6; + function init() { + game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png'); + game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png'); + game.loader.addImageFile('ball3', 'assets/sprites/red_ball.png'); + game.loader.addImageFile('ball4', 'assets/sprites/purple_ball.png'); + game.loader.addImageFile('ball5', 'assets/sprites/blue_ball.png'); + game.loader.addImageFile('ball6', 'assets/sprites/green_ball.png'); + game.loader.load(); + } + function makeEmitter(emitter, x, y, graphic) { + emitter = game.add.emitter(x, y); + emitter.gravity = 100; + emitter.bounce = 0.5; + if(x == 0) { + emitter.setXSpeed(200, 250); + } else { + emitter.setXSpeed(-200, -250); + } + emitter.setYSpeed(-50, -10); + emitter.makeParticles(graphic, 250, false, 0); + return emitter; + } + function create() { + emitter1 = makeEmitter(emitter1, 0, 50, 'ball1'); + emitter2 = makeEmitter(emitter2, 0, 250, 'ball2'); + emitter3 = makeEmitter(emitter3, 0, 450, 'ball3'); + emitter4 = makeEmitter(emitter4, game.stage.width, 50, 'ball4'); + emitter5 = makeEmitter(emitter5, game.stage.width, 250, 'ball5'); + emitter6 = makeEmitter(emitter6, game.stage.width, 450, 'ball6'); + emitter1.start(false, 50, 0.05); + emitter2.start(false, 50, 0.05); + emitter3.start(false, 50, 0.05); + emitter4.start(false, 50, 0.05); + emitter5.start(false, 50, 0.05); + emitter6.start(false, 50, 0.05); + } + function update() { + //game.collide(leftEmitter, rightEmitter); + } +})(); diff --git a/Tests/particles/multiple streams.ts b/Tests/particles/multiple streams.ts new file mode 100644 index 00000000..a2335dd4 --- /dev/null +++ b/Tests/particles/multiple streams.ts @@ -0,0 +1,73 @@ +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + + var emitter1: Phaser.Emitter; + var emitter2: Phaser.Emitter; + var emitter3: Phaser.Emitter; + var emitter4: Phaser.Emitter; + var emitter5: Phaser.Emitter; + var emitter6: Phaser.Emitter; + + function init() { + + game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png'); + game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png'); + game.loader.addImageFile('ball3', 'assets/sprites/red_ball.png'); + game.loader.addImageFile('ball4', 'assets/sprites/purple_ball.png'); + game.loader.addImageFile('ball5', 'assets/sprites/blue_ball.png'); + game.loader.addImageFile('ball6', 'assets/sprites/green_ball.png'); + + game.loader.load(); + + } + + function makeEmitter(emitter, x, y, graphic) { + + emitter = game.add.emitter(x, y); + emitter.gravity = 100; + emitter.bounce = 0.5; + + if (x == 0) + { + emitter.setXSpeed(200, 250); + } + else + { + emitter.setXSpeed(-200, -250); + } + + emitter.setYSpeed(-50, -10); + emitter.makeParticles(graphic, 250, false, 0); + + return emitter; + + } + + function create() { + + emitter1 = makeEmitter(emitter1, 0, 50, 'ball1'); + emitter2 = makeEmitter(emitter2, 0, 250, 'ball2'); + emitter3 = makeEmitter(emitter3, 0, 450, 'ball3'); + emitter4 = makeEmitter(emitter4, game.stage.width, 50, 'ball4'); + emitter5 = makeEmitter(emitter5, game.stage.width, 250, 'ball5'); + emitter6 = makeEmitter(emitter6, game.stage.width, 450, 'ball6'); + + emitter1.start(false, 50, 0.05); + emitter2.start(false, 50, 0.05); + emitter3.start(false, 50, 0.05); + emitter4.start(false, 50, 0.05); + emitter5.start(false, 50, 0.05); + emitter6.start(false, 50, 0.05); + + } + + function update() { + + //game.collide(leftEmitter, rightEmitter); + + } + +})(); diff --git a/Tests/particles/sprite emitter.js b/Tests/particles/sprite emitter.js new file mode 100644 index 00000000..c4cf4e8f --- /dev/null +++ b/Tests/particles/sprite emitter.js @@ -0,0 +1,46 @@ +var __extends = this.__extends || function (d, b) { + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +/// +/// +/// +// Actually we could achieve the same result as this by using a sprite sheet and basic Particle +// but it still shows you how to use it properly from TypeScript, so it was worth making +var customParticle = (function (_super) { + __extends(customParticle, _super); + function customParticle(game) { + _super.call(this, game); + var s = [ + 'carrot', + 'melon', + 'eggplant', + 'mushroom', + 'pineapple' + ]; + this.texture.loadImage(game.math.getRandom(s)); + } + return customParticle; +})(Phaser.Particle); +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create); + var emitter; + function init() { + game.loader.addImageFile('carrot', 'assets/sprites/carrot.png'); + game.loader.addImageFile('melon', 'assets/sprites/melon.png'); + game.loader.addImageFile('eggplant', 'assets/sprites/eggplant.png'); + game.loader.addImageFile('mushroom', 'assets/sprites/mushroom.png'); + game.loader.addImageFile('pineapple', 'assets/sprites/pineapple.png'); + game.loader.load(); + } + function create() { + emitter = game.add.emitter(game.stage.centerX, 50); + emitter.gravity = 100; + // Here we tell the emitter to use our customParticle class + // The customParticle needs to extend Particle and must take game:Game as the first constructor parameter, otherwise it's free as a bird + emitter.particleClass = customParticle; + emitter.makeParticles(null, 500, false, 0); + emitter.start(false, 10, 0.05); + } +})(); diff --git a/Tests/particles/sprite emitter.ts b/Tests/particles/sprite emitter.ts new file mode 100644 index 00000000..11b70ed1 --- /dev/null +++ b/Tests/particles/sprite emitter.ts @@ -0,0 +1,52 @@ +/// +/// +/// + +// Actually we could achieve the same result as this by using a sprite sheet and basic Particle +// but it still shows you how to use it properly from TypeScript, so it was worth making +class customParticle extends Phaser.Particle { + + constructor(game:Phaser.Game) { + + super(game); + + var s = ['carrot', 'melon', 'eggplant', 'mushroom', 'pineapple']; + + this.texture.loadImage(game.math.getRandom(s)); + } + +} + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create); + + var emitter: Phaser.Emitter; + + function init() { + + game.loader.addImageFile('carrot', 'assets/sprites/carrot.png'); + game.loader.addImageFile('melon', 'assets/sprites/melon.png'); + game.loader.addImageFile('eggplant', 'assets/sprites/eggplant.png'); + game.loader.addImageFile('mushroom', 'assets/sprites/mushroom.png'); + game.loader.addImageFile('pineapple', 'assets/sprites/pineapple.png'); + + game.loader.load(); + + } + + function create() { + + emitter = game.add.emitter(game.stage.centerX, 50); + emitter.gravity = 100; + + // Here we tell the emitter to use our customParticle class + // The customParticle needs to extend Particle and must take game:Game as the first constructor parameter, otherwise it's free as a bird + emitter.particleClass = customParticle; + + emitter.makeParticles(null, 500, false, 0); + emitter.start(false, 10, 0.05); + + } + +})(); diff --git a/Tests/particles/when particles collide.js b/Tests/particles/when particles collide.js new file mode 100644 index 00000000..e5608c44 --- /dev/null +++ b/Tests/particles/when particles collide.js @@ -0,0 +1,30 @@ +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + var leftEmitter; + var rightEmitter; + function init() { + game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png'); + game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png'); + game.loader.load(); + } + function create() { + leftEmitter = game.add.emitter(0, game.stage.centerY - 200); + leftEmitter.gravity = 100; + leftEmitter.bounce = 0.5; + leftEmitter.setXSpeed(100, 200); + leftEmitter.setYSpeed(-50, 50); + leftEmitter.makeParticles('ball1', 250, false, 1); + rightEmitter = game.add.emitter(game.stage.width + 20, game.stage.centerY - 200); + rightEmitter.gravity = 100; + rightEmitter.bounce = 0.5; + rightEmitter.setXSpeed(-100, -200); + rightEmitter.setYSpeed(-50, 50); + rightEmitter.makeParticles('ball2', 250, false, 1); + leftEmitter.start(false, 50, 0.05); + rightEmitter.start(false, 50, 0.05); + } + function update() { + //game.collide(leftEmitter, rightEmitter); + } +})(); diff --git a/Tests/particles/when particles collide.ts b/Tests/particles/when particles collide.ts new file mode 100644 index 00000000..5a49f663 --- /dev/null +++ b/Tests/particles/when particles collide.ts @@ -0,0 +1,46 @@ +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + + var leftEmitter: Phaser.Emitter; + var rightEmitter: Phaser.Emitter; + + function init() { + + game.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png'); + game.loader.addImageFile('ball2', 'assets/sprites/yellow_ball.png'); + + game.loader.load(); + + } + + function create() { + + leftEmitter = game.add.emitter(0, game.stage.centerY - 200); + leftEmitter.gravity = 100; + leftEmitter.bounce = 0.5; + leftEmitter.setXSpeed(100, 200); + leftEmitter.setYSpeed(-50, 50); + leftEmitter.makeParticles('ball1', 250, false, 1); + + rightEmitter = game.add.emitter(game.stage.width + 20, game.stage.centerY - 200); + rightEmitter.gravity = 100; + rightEmitter.bounce = 0.5; + rightEmitter.setXSpeed(-100, -200); + rightEmitter.setYSpeed(-50, 50); + rightEmitter.makeParticles('ball2', 250, false, 1); + + leftEmitter.start(false, 50, 0.05); + rightEmitter.start(false, 50, 0.05); + + } + + function update() { + + //game.collide(leftEmitter, rightEmitter); + + } + +})(); diff --git a/Tests/phaser.js b/Tests/phaser.js index c3baaccc..fc768976 100644 --- a/Tests/phaser.js +++ b/Tests/phaser.js @@ -406,9 +406,10 @@ var Phaser; * @param {Number} height Desired height of this node. * @param {Number} parent The parent branch or node. Pass null to create a root. */ - function QuadTree(x, y, width, height, parent) { + function QuadTree(manager, x, y, width, height, parent) { if (typeof parent === "undefined") { parent = null; } _super.call(this, x, y, width, height); + QuadTree.physics = manager; this._headA = this._tailA = new Phaser.LinkedList(); this._headB = this._tailB = new Phaser.LinkedList(); //Copy the parent's children (if there are any) @@ -562,14 +563,14 @@ var Phaser; if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) { if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) { if(this._northWestTree == null) { - this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northWestTree.addObject(); return; } if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) { if(this._southWestTree == null) { - this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southWestTree.addObject(); return; @@ -578,14 +579,14 @@ var Phaser; if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) { if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) { if(this._northEastTree == null) { - this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northEastTree.addObject(); return; } if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) { if(this._southEastTree == null) { - this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southEastTree.addObject(); return; @@ -594,25 +595,25 @@ var Phaser; //If it wasn't completely contained we have to check out the partial overlaps if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) { if(this._northWestTree == null) { - this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northWestTree.addObject(); } if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) { if(this._northEastTree == null) { - this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northEastTree.addObject(); } if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) { if(this._southEastTree == null) { - this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southEastTree.addObject(); } if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) { if(this._southWestTree == null) { - this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southWestTree.addObject(); } @@ -707,7 +708,8 @@ var Phaser; QuadTree._iterator = QuadTree._iterator.next; continue; } - if(QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) { + //if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) + if(QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body)) { //Execute callback functions if they exist if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject)) { this._overlapProcessed = true; @@ -1351,7 +1353,15 @@ var Phaser; while(this._i < this.length) { this._member = this.members[this._i++]; if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) { - this._member.render.call(renderer, camera, this._member); + //this._member.render.call(renderer, camera, this._member); + // call = context first, then parameters + if(this._member.type == Phaser.Types.GROUP) { + //console.log('group rend'); + this._member.render.call(this._member, renderer, camera, this._member); + //this._member.render.call(this, renderer, camera, this._member); + } else { + this._member.render.call(renderer, camera, this._member); + } } } if(this.alpha > 0) { @@ -5284,6 +5294,8 @@ var Phaser; sprite.y = y; sprite.body.velocity.x = 0; sprite.body.velocity.y = 0; + sprite.body.position.x = x; + sprite.body.position.y = y; }; SpriteUtils.setBounds = /** * Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere @@ -5408,8 +5420,9 @@ var Phaser; * @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean * @return {Sprite} Sprite instance itself. */ - function (key, clearAnimations) { + function (key, clearAnimations, updateBody) { if (typeof clearAnimations === "undefined") { clearAnimations = true; } + if (typeof updateBody === "undefined") { updateBody = true; } if(clearAnimations && this._sprite.animations.frameData !== null) { this._sprite.animations.destroy(); } @@ -5421,6 +5434,10 @@ var Phaser; this._sprite.frameBounds.width = this.width; this._sprite.frameBounds.height = this.height; } + if(updateBody) { + this._sprite.body.bounds.width = this.width; + this._sprite.body.bounds.height = this.height; + } } }; Texture.prototype.loadDynamicTexture = /** @@ -7563,6 +7580,7 @@ var Phaser; */ function Particle(game) { _super.call(this, game); + this.body.type = Phaser.Types.BODY_DYNAMIC; this.lifespan = 0; this.friction = 500; } @@ -7571,7 +7589,7 @@ var Phaser; * be dead yet, and then has some special bounce behavior if there is some gravity on it. */ function () { - //lifespan behavior + // Lifespan behavior if(this.lifespan <= 0) { return; } @@ -7609,6 +7627,7 @@ var Phaser; * You can override this to add custom behavior like a sound or AI or something. */ function () { + console.log('particle emitted', this.width, this.height); }; return Particle; })(Phaser.Sprite); @@ -7660,6 +7679,9 @@ var Phaser; this._counter = 0; this._explode = true; this.on = false; + this.exists = true; + this.active = true; + this.visible = true; } Emitter.prototype.destroy = /** * Clean up memory. @@ -7718,12 +7740,6 @@ var Phaser; } */ } else { - /* - if (BakedRotations > 0) - particle.loadRotatedGraphic(Graphics,BakedRotations); - else - particle.loadGraphic(Graphics); - */ if(graphics) { particle.texture.loadImage(graphics); } @@ -7737,11 +7753,17 @@ var Phaser; particle.body.allowCollisions = Phaser.Types.NONE; } particle.exists = false; + // Center it + particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight); this.add(particle); i++; } return this; }; + Emitter.prototype.preUpdate = function () { + }; + Emitter.prototype.postUpdate = function () { + }; Emitter.prototype.update = /** * Called automatically by the game loop, decides when to launch particles and when to "die". */ @@ -10646,7 +10668,7 @@ var Phaser; if(body.type == Phaser.Types.BODY_DISABLED) { return; } - this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2; + this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2; body.angularVelocity += this._velocityDelta; body.angle += body.angularVelocity * this.game.time.elapsed; body.angularVelocity += this._velocityDelta; @@ -10711,15 +10733,7 @@ var Phaser; }; PhysicsManager.prototype.checkHullIntersection = function (body1, body2) { return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight)); - //if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight)) - //{ - // return true; - //} - //else - //{ - // return false; - //} - }; + }; PhysicsManager.prototype.separateBodyX = /** * Separates the two objects on their x axis * @param object1 The first GameObject to separate @@ -11158,7 +11172,7 @@ var Phaser; object2 = null; } Phaser.QuadTree.divisions = this.worldDivisions; - this._quadTree = new Phaser.QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); + this._quadTree = new Phaser.QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); this._quadTree.load(object1, object2, notifyCallback, processCallback, context); this._quadTreeResult = this._quadTree.execute(); this._quadTree.destroy(); diff --git a/Tests/sprites/sprite origin 2.js b/Tests/sprites/sprite origin 2.js index a1da5480..dd0f7996 100644 --- a/Tests/sprites/sprite origin 2.js +++ b/Tests/sprites/sprite origin 2.js @@ -16,7 +16,7 @@ // This will cause it to rotate on its center fuji.origin.setTo(160, 100); game.add.tween(fuji).to({ - rotation: 360 + angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } })(); diff --git a/Tests/sprites/sprite origin 2.ts b/Tests/sprites/sprite origin 2.ts index 237c0f9a..6c3edb82 100644 --- a/Tests/sprites/sprite origin 2.ts +++ b/Tests/sprites/sprite origin 2.ts @@ -26,7 +26,7 @@ // This will cause it to rotate on its center fuji.origin.setTo(160, 100); - game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } diff --git a/Tests/sprites/sprite origin 3.js b/Tests/sprites/sprite origin 3.js index 9f91c600..6a5fad8c 100644 --- a/Tests/sprites/sprite origin 3.js +++ b/Tests/sprites/sprite origin 3.js @@ -16,7 +16,7 @@ // Here we set the origin to be the bottom-right of the sprite fuji.origin.setTo(320, 200); game.add.tween(fuji).to({ - rotation: 360 + angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } })(); diff --git a/Tests/sprites/sprite origin 3.ts b/Tests/sprites/sprite origin 3.ts index fff4fbf8..fb70a699 100644 --- a/Tests/sprites/sprite origin 3.ts +++ b/Tests/sprites/sprite origin 3.ts @@ -26,7 +26,7 @@ // Here we set the origin to be the bottom-right of the sprite fuji.origin.setTo(320, 200); - game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } diff --git a/Tests/sprites/sprite origin 4.js b/Tests/sprites/sprite origin 4.js index 4bd6a0bc..cf9d004b 100644 --- a/Tests/sprites/sprite origin 4.js +++ b/Tests/sprites/sprite origin 4.js @@ -17,7 +17,7 @@ // Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time fuji.origin.setTo(160, 100); game.add.tween(fuji).to({ - rotation: 360 + angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); tweenUp = game.add.tween(fuji.scale); tweenUp.onComplete.add(scaleDown, this); diff --git a/Tests/sprites/sprite origin 4.ts b/Tests/sprites/sprite origin 4.ts index d16afdda..e178a95a 100644 --- a/Tests/sprites/sprite origin 4.ts +++ b/Tests/sprites/sprite origin 4.ts @@ -27,7 +27,7 @@ // Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time fuji.origin.setTo(160, 100); - game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(fuji).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); tweenUp = game.add.tween(fuji.scale); tweenUp.onComplete.add(scaleDown, this); diff --git a/Tests/tweens/tween loop 1.js b/Tests/tweens/tween loop 1.js index f411e934..40086aa8 100644 --- a/Tests/tweens/tween loop 1.js +++ b/Tests/tweens/tween loop 1.js @@ -12,9 +12,11 @@ swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); // Increase the size of the sprite a little so it covers the edges of the stage swirl.scale.setTo(1.4, 1.4); + // Set the origin to the middle of the Sprite to get the effect we need + swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight); // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) game.add.tween(swirl).to({ - rotation: 360 + angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } })(); diff --git a/Tests/tweens/tween loop 1.ts b/Tests/tweens/tween loop 1.ts index 61cc8e97..5dd401fc 100644 --- a/Tests/tweens/tween loop 1.ts +++ b/Tests/tweens/tween loop 1.ts @@ -22,8 +22,11 @@ // Increase the size of the sprite a little so it covers the edges of the stage swirl.scale.setTo(1.4, 1.4); + // Set the origin to the middle of the Sprite to get the effect we need + swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight); + // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) - game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(swirl).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } diff --git a/Tests/tweens/tween loop 2.js b/Tests/tweens/tween loop 2.js index 0a396ae9..8993cbe7 100644 --- a/Tests/tweens/tween loop 2.js +++ b/Tests/tweens/tween loop 2.js @@ -12,8 +12,12 @@ swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); // Increase the size of the sprite a little so it covers the edges of the stage swirl.scale.setTo(1.4, 1.4); + // Set the origin to the middle of the Sprite to get the effect we need + swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight); // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) - //game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(swirl).to({ + angle: 360 + }, 2000, Phaser.Easing.Linear.None, true, 0, true); game.add.tween(swirl.scale).to({ x: 4, y: 4 diff --git a/Tests/tweens/tween loop 2.ts b/Tests/tweens/tween loop 2.ts index c5b3be7b..95c44335 100644 --- a/Tests/tweens/tween loop 2.ts +++ b/Tests/tweens/tween loop 2.ts @@ -22,8 +22,11 @@ // Increase the size of the sprite a little so it covers the edges of the stage swirl.scale.setTo(1.4, 1.4); + // Set the origin to the middle of the Sprite to get the effect we need + swirl.origin.setTo(swirl.frameBounds.halfWidth, swirl.frameBounds.halfHeight); + // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) - //game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(swirl).to({ angle: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); game.add.tween(swirl.scale).to({ x: 4, y: 4 }, 1000, Phaser.Easing.Linear.None, true, 0, true, true); } diff --git a/build/phaser.d.ts b/build/phaser.d.ts index 752795df..32a5f43c 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -320,7 +320,7 @@ module Phaser { * @param {Number} height Desired height of this node. * @param {Number} parent The parent branch or node. Pass null to create a root. */ - constructor(x: number, y: number, width: number, height: number, parent?: QuadTree); + constructor(manager: Physics.PhysicsManager, x: number, y: number, width: number, height: number, parent?: QuadTree); private _iterator; private _ot; private _i; @@ -329,6 +329,7 @@ module Phaser { private _l; private _overlapProcessed; private _checkObject; + static physics: Physics.PhysicsManager; /** * Flag for specifying that you want to add an object to the A list. */ @@ -3178,7 +3179,7 @@ module Phaser.Components { * @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean * @return {Sprite} Sprite instance itself. */ - public loadImage(key: string, clearAnimations?: bool): void; + public loadImage(key: string, clearAnimations?: bool, updateBody?: bool): void; /** * Load a DynamicTexture as its texture. * @param texture {DynamicTexture} The texture object to be used by this sprite. @@ -4298,6 +4299,10 @@ module Phaser { */ public alive: bool; /** + * + */ + public active: bool; + /** * The minimum possible velocity of a particle. * The default value is (-100,-100). */ @@ -4383,6 +4388,8 @@ module Phaser { * @return This Emitter instance (nice for chaining stuff together, if you're into that). */ public makeParticles(graphics, quantity?: number, multiple?: bool, collide?: number): Emitter; + public preUpdate(): void; + public postUpdate(): void; /** * Called automatically by the game loop, decides when to launch particles and when to "die". */ @@ -6133,7 +6140,7 @@ module Phaser.Physics { * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ public separate(body1: Body, body2: Body): bool; - private checkHullIntersection(body1, body2); + public checkHullIntersection(body1: Body, body2: Body): bool; /** * Separates the two objects on their x axis * @param object1 The first GameObject to separate diff --git a/build/phaser.js b/build/phaser.js index c3baaccc..fc768976 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -406,9 +406,10 @@ var Phaser; * @param {Number} height Desired height of this node. * @param {Number} parent The parent branch or node. Pass null to create a root. */ - function QuadTree(x, y, width, height, parent) { + function QuadTree(manager, x, y, width, height, parent) { if (typeof parent === "undefined") { parent = null; } _super.call(this, x, y, width, height); + QuadTree.physics = manager; this._headA = this._tailA = new Phaser.LinkedList(); this._headB = this._tailB = new Phaser.LinkedList(); //Copy the parent's children (if there are any) @@ -562,14 +563,14 @@ var Phaser; if((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX)) { if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) { if(this._northWestTree == null) { - this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northWestTree.addObject(); return; } if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) { if(this._southWestTree == null) { - this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southWestTree.addObject(); return; @@ -578,14 +579,14 @@ var Phaser; if((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge)) { if((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY)) { if(this._northEastTree == null) { - this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northEastTree.addObject(); return; } if((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge)) { if(this._southEastTree == null) { - this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southEastTree.addObject(); return; @@ -594,25 +595,25 @@ var Phaser; //If it wasn't completely contained we have to check out the partial overlaps if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) { if(this._northWestTree == null) { - this._northWestTree = new QuadTree(this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northWestTree.addObject(); } if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY)) { if(this._northEastTree == null) { - this._northEastTree = new QuadTree(this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); + this._northEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._topEdge, this._halfWidth, this._halfHeight, this); } this._northEastTree.addObject(); } if((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) { if(this._southEastTree == null) { - this._southEastTree = new QuadTree(this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southEastTree = new QuadTree(QuadTree.physics, this._midpointX, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southEastTree.addObject(); } if((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge)) { if(this._southWestTree == null) { - this._southWestTree = new QuadTree(this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); + this._southWestTree = new QuadTree(QuadTree.physics, this._leftEdge, this._midpointY, this._halfWidth, this._halfHeight, this); } this._southWestTree.addObject(); } @@ -707,7 +708,8 @@ var Phaser; QuadTree._iterator = QuadTree._iterator.next; continue; } - if(QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) { + //if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds)) + if(QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body)) { //Execute callback functions if they exist if((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject)) { this._overlapProcessed = true; @@ -1351,7 +1353,15 @@ var Phaser; while(this._i < this.length) { this._member = this.members[this._i++]; if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) { - this._member.render.call(renderer, camera, this._member); + //this._member.render.call(renderer, camera, this._member); + // call = context first, then parameters + if(this._member.type == Phaser.Types.GROUP) { + //console.log('group rend'); + this._member.render.call(this._member, renderer, camera, this._member); + //this._member.render.call(this, renderer, camera, this._member); + } else { + this._member.render.call(renderer, camera, this._member); + } } } if(this.alpha > 0) { @@ -5284,6 +5294,8 @@ var Phaser; sprite.y = y; sprite.body.velocity.x = 0; sprite.body.velocity.y = 0; + sprite.body.position.x = x; + sprite.body.position.y = y; }; SpriteUtils.setBounds = /** * Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere @@ -5408,8 +5420,9 @@ var Phaser; * @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean * @return {Sprite} Sprite instance itself. */ - function (key, clearAnimations) { + function (key, clearAnimations, updateBody) { if (typeof clearAnimations === "undefined") { clearAnimations = true; } + if (typeof updateBody === "undefined") { updateBody = true; } if(clearAnimations && this._sprite.animations.frameData !== null) { this._sprite.animations.destroy(); } @@ -5421,6 +5434,10 @@ var Phaser; this._sprite.frameBounds.width = this.width; this._sprite.frameBounds.height = this.height; } + if(updateBody) { + this._sprite.body.bounds.width = this.width; + this._sprite.body.bounds.height = this.height; + } } }; Texture.prototype.loadDynamicTexture = /** @@ -7563,6 +7580,7 @@ var Phaser; */ function Particle(game) { _super.call(this, game); + this.body.type = Phaser.Types.BODY_DYNAMIC; this.lifespan = 0; this.friction = 500; } @@ -7571,7 +7589,7 @@ var Phaser; * be dead yet, and then has some special bounce behavior if there is some gravity on it. */ function () { - //lifespan behavior + // Lifespan behavior if(this.lifespan <= 0) { return; } @@ -7609,6 +7627,7 @@ var Phaser; * You can override this to add custom behavior like a sound or AI or something. */ function () { + console.log('particle emitted', this.width, this.height); }; return Particle; })(Phaser.Sprite); @@ -7660,6 +7679,9 @@ var Phaser; this._counter = 0; this._explode = true; this.on = false; + this.exists = true; + this.active = true; + this.visible = true; } Emitter.prototype.destroy = /** * Clean up memory. @@ -7718,12 +7740,6 @@ var Phaser; } */ } else { - /* - if (BakedRotations > 0) - particle.loadRotatedGraphic(Graphics,BakedRotations); - else - particle.loadGraphic(Graphics); - */ if(graphics) { particle.texture.loadImage(graphics); } @@ -7737,11 +7753,17 @@ var Phaser; particle.body.allowCollisions = Phaser.Types.NONE; } particle.exists = false; + // Center it + particle.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight); this.add(particle); i++; } return this; }; + Emitter.prototype.preUpdate = function () { + }; + Emitter.prototype.postUpdate = function () { + }; Emitter.prototype.update = /** * Called automatically by the game loop, decides when to launch particles and when to "die". */ @@ -10646,7 +10668,7 @@ var Phaser; if(body.type == Phaser.Types.BODY_DISABLED) { return; } - this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2; + this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2; body.angularVelocity += this._velocityDelta; body.angle += body.angularVelocity * this.game.time.elapsed; body.angularVelocity += this._velocityDelta; @@ -10711,15 +10733,7 @@ var Phaser; }; PhysicsManager.prototype.checkHullIntersection = function (body1, body2) { return ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight)); - //if ((body1.hullX + body1.hullWidth > body2.hullX) && (body1.hullX < body2.hullX + body2.hullWidth) && (body1.hullY + body1.hullHeight > body2.hullY) && (body1.hullY < body2.hullY + body2.hullHeight)) - //{ - // return true; - //} - //else - //{ - // return false; - //} - }; + }; PhysicsManager.prototype.separateBodyX = /** * Separates the two objects on their x axis * @param object1 The first GameObject to separate @@ -11158,7 +11172,7 @@ var Phaser; object2 = null; } Phaser.QuadTree.divisions = this.worldDivisions; - this._quadTree = new Phaser.QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); + this._quadTree = new Phaser.QuadTree(this, this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); this._quadTree.load(object1, object2, notifyCallback, processCallback, context); this._quadTreeResult = this._quadTree.execute(); this._quadTree.destroy();