Skip to content

Commit b666874

Browse files
committed
Fixed Body.reset and Tanks game.
1 parent dc434dd commit b666874

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

examples/games/tanks.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ var turret;
9898

9999
var enemies;
100100
var enemyBullets;
101+
var enemiesTotal = 0;
102+
var enemiesAlive = 0;
101103
var explosions;
102104

103105
var logo;
@@ -147,7 +149,10 @@ function create () {
147149
// Create some baddies to waste :)
148150
enemies = [];
149151

150-
for (var i = 0; i < 20; i++)
152+
enemiesTotal = 20;
153+
enemiesAlive = 20;
154+
155+
for (var i = 0; i < enemiesTotal; i++)
151156
{
152157
enemies.push(new EnemyTank(i, game, tank, enemyBullets));
153158
}
@@ -160,7 +165,7 @@ function create () {
160165
bullets = game.add.group();
161166
bullets.enableBody = true;
162167
bullets.physicsBodyType = Phaser.Physics.ARCADE;
163-
bullets.createMultiple(30, 'bullet');
168+
bullets.createMultiple(30, 'bullet', 0, false);
164169
bullets.setAll('anchor.x', 0.5);
165170
bullets.setAll('anchor.y', 0.5);
166171
bullets.setAll('outOfBoundsKill', true);
@@ -203,10 +208,13 @@ function update () {
203208

204209
game.physics.arcade.overlap(enemyBullets, tank, bulletHitPlayer, null, this);
205210

211+
enemiesAlive = 0;
212+
206213
for (var i = 0; i < enemies.length; i++)
207214
{
208215
if (enemies[i].alive)
209216
{
217+
enemiesAlive++;
210218
game.physics.arcade.collide(tank, enemies[i].tank);
211219
game.physics.arcade.overlap(bullets, enemies[i].tank, bulletHitEnemy, null, this);
212220
enemies[i].update();
@@ -299,7 +307,8 @@ function fire () {
299307

300308
function render () {
301309

302-
// game.debug.text('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.total, 32, 32);
310+
// game.debug.text('Active Bullets: ' + bullets.countLiving() + ' / ' + bullets.length, 32, 32);
311+
game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 32);
303312

304313
}
305314

src/physics/arcade/Body.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,21 +533,21 @@ Phaser.Physics.Arcade.Body.prototype = {
533533
* Resets all Body values (velocity, acceleration, rotation, etc)
534534
*
535535
* @method Phaser.Physics.Arcade#reset
536+
* @param {number} x - The new x position of the Body.
537+
* @param {number} y - The new x position of the Body.
536538
*/
537-
reset: function () {
539+
reset: function (x, y) {
538540

539541
this.velocity.setTo(0, 0);
540542
this.acceleration.setTo(0, 0);
541543

542544
this.angularVelocity = 0;
543545
this.angularAcceleration = 0;
544-
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
545-
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
546-
this.preRotation = this.sprite.angle;
547546

548-
this.x = this.preX;
549-
this.y = this.preY;
550-
this.rotation = this.preRotation;
547+
this.position.set(x, y);
548+
this.prev.set(x, y);
549+
this.rotation = this.sprite.rotation;
550+
this.preRotation = this.rotation;
551551

552552
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
553553

0 commit comments

Comments
 (0)