Skip to content

Commit 24c809d

Browse files
committed
Final body / physics / bounds fixes. Also updated various examples, optimised Sprite core loop and enhanced the Invaders example.
1 parent 3de6290 commit 24c809d

9 files changed

Lines changed: 383 additions & 197 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ Change Log
4040
Version 1.1.2
4141

4242
* New: You'll now find a complete Basic project Template in the resources/Project Templates folder. Will add more complex ones soon.
43+
* New: Phaser.Button now has the ability to set over/out/up/down sound effects so they play automatically based on those events.
44+
* Updated: Fixed a few final bugs in the Sprite body and bounds calculations, in turn this resolved the Tilemap collision issues in the 1.1 release.
45+
* Updated: Finished documentation for the Phaser.Button class.
4346
* Fixed issue 135 - Added typeof checks into most ArcadePhysics functions to avoid errors with zero values.
4447
* Fixed issue 136 - distanceTo using worldX/Y instead of x/y.
4548
* Added init method to plugins, to be called as they are added to the PluginManager (thanks beeglebug)
4649
* If you pause an Animation, when you next play it it'll resume (un-pause itself).
47-
* Started work on fixing the body / camera / tilemap issue - pretty much sorted now I think, more tests needed.
48-
49-
50+
* New: Physics.Body now has a center property (issue 142, thanks MikeMnD)
51+
* Updated: Fixed the Invaders game sample and enhanced it, also fixed lots of "cursor key moves the page" examples.
5052

5153

5254
Version 1.1.1 - October 26th 2013

examples/camera/basic follow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ function render() {
6767
game.debug.renderSpriteCoords(player, 32, 200);
6868
game.debug.renderSpriteCoords(fixed, 600, 200);
6969

70-
game.debug.renderSpriteCoords(game.world._container, 32, 400);
70+
// game.debug.renderSpriteCoords(game.world._container, 32, 400);
7171

7272
}

examples/games/invaders.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ function preload() {
77
game.load.image('bullet', 'assets/misc/bullet0.png');
88
game.load.image('alien', 'assets/sprites/space-baddie.png');
99
game.load.image('ship', 'assets/sprites/shmup-ship.png');
10+
game.load.spritesheet('kaboom', 'assets/games/tanks/explosion.png', 64, 64, 23);
11+
game.load.image('starfield', 'assets/misc/starfield.jpg');
1012

1113
}
1214

1315
var player;
1416
var aliens;
1517
var bullets;
1618
var bulletTime = 0;
19+
var cursors;
20+
var fireButton;
21+
var explosions;
1722

1823
function create() {
1924

25+
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
26+
2027
player = game.add.sprite(400, 500, 'ship');
2128
player.anchor.setTo(0.5, 0.5);
2229

@@ -33,21 +40,29 @@ function create() {
3340
aliens.x = 100;
3441
aliens.y = 50;
3542

36-
bullets = game.add.group(null, 'bullets');
43+
// Our bullet group
44+
bullets = game.add.group();
45+
bullets.createMultiple(30, 'bullet');
46+
bullets.setAll('anchor.x', 0.5);
47+
bullets.setAll('anchor.y', 1);
48+
bullets.setAll('outOfBoundsKill', true);
49+
50+
// Explosion pool
51+
explosions = game.add.group();
3752

3853
for (var i = 0; i < 10; i++)
3954
{
40-
var b = bullets.create(0, 0, 'bullet');
41-
b.name = 'bullet' + i;
42-
b.exists = false;
43-
b.visible = false;
44-
b.anchor.setTo(0.5, 1);
45-
b.events.onOutOfBounds.add(resetBullet, this);
55+
var explosionAnimation = explosions.create(0, 0, 'kaboom', [0], false);
56+
explosionAnimation.anchor.setTo(0.5, 0.5);
57+
explosionAnimation.animations.add('kaboom');
4658
}
4759

4860
var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true);
4961
tween.onComplete.add(descend, this);
5062

63+
cursors = game.input.keyboard.createCursorKeys();
64+
fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
65+
5166
}
5267

5368

@@ -60,16 +75,16 @@ function update() {
6075
player.body.velocity.x = 0;
6176
player.body.velocity.y = 0;
6277

63-
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
78+
if (cursors.left.isDown)
6479
{
6580
player.body.velocity.x = -200;
6681
}
67-
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
82+
else if (cursors.right.isDown)
6883
{
6984
player.body.velocity.x = 200;
7085
}
7186

72-
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
87+
if (fireButton.isDown)
7388
{
7489
fireBullet();
7590
}
@@ -104,16 +119,11 @@ function collisionHandler (bullet, alien) {
104119
bullet.kill();
105120
alien.kill();
106121

107-
}
108-
109-
function render () {
110-
111-
// aliens.forEach(renderBounds, this);
112-
113-
game.debug.renderQuadTree(game.physics.quadTree);
122+
var explosionAnimation = explosions.getFirstDead();
123+
explosionAnimation.reset(alien.body.x, alien.body.y);
124+
explosionAnimation.play('kaboom', 30, false, true);
114125

115126
}
116127

117-
function renderBounds(s) {
118-
game.debug.renderSpriteBounds(s, 'rgba(0,0,255,0.4)', true);
128+
function render () {
119129
}

resources/Project Templates/Basic/Boot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
BasicGame = {};
12

23
BasicGame.Boot = function (game) {
34

resources/Project Templates/Basic/Game.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
BasicGame.Game = function (game) {
23

34
// Honestly, just about anything could go here.

resources/Project Templates/Basic/MainMenu.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
BasicGame.MainMenu = function (game) {
23

34
this.music = null;

0 commit comments

Comments
 (0)