Final body / physics / bounds fixes. Also updated various examples, optimised Sprite core loop and enhanced the Invaders example.

This commit is contained in:
photonstorm
2013-10-30 03:46:52 +00:00
parent 3de62907a0
commit 24c809dd5f
9 changed files with 384 additions and 198 deletions
+1 -1
View File
@@ -67,6 +67,6 @@ function render() {
game.debug.renderSpriteCoords(player, 32, 200);
game.debug.renderSpriteCoords(fixed, 600, 200);
game.debug.renderSpriteCoords(game.world._container, 32, 400);
// game.debug.renderSpriteCoords(game.world._container, 32, 400);
}
+29 -19
View File
@@ -7,6 +7,8 @@ function preload() {
game.load.image('bullet', 'assets/misc/bullet0.png');
game.load.image('alien', 'assets/sprites/space-baddie.png');
game.load.image('ship', 'assets/sprites/shmup-ship.png');
game.load.spritesheet('kaboom', 'assets/games/tanks/explosion.png', 64, 64, 23);
game.load.image('starfield', 'assets/misc/starfield.jpg');
}
@@ -14,9 +16,14 @@ var player;
var aliens;
var bullets;
var bulletTime = 0;
var cursors;
var fireButton;
var explosions;
function create() {
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
player = game.add.sprite(400, 500, 'ship');
player.anchor.setTo(0.5, 0.5);
@@ -33,21 +40,29 @@ function create() {
aliens.x = 100;
aliens.y = 50;
bullets = game.add.group(null, 'bullets');
// Our bullet group
bullets = game.add.group();
bullets.createMultiple(30, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 1);
bullets.setAll('outOfBoundsKill', true);
// Explosion pool
explosions = game.add.group();
for (var i = 0; i < 10; i++)
{
var b = bullets.create(0, 0, 'bullet');
b.name = 'bullet' + i;
b.exists = false;
b.visible = false;
b.anchor.setTo(0.5, 1);
b.events.onOutOfBounds.add(resetBullet, this);
var explosionAnimation = explosions.create(0, 0, 'kaboom', [0], false);
explosionAnimation.anchor.setTo(0.5, 0.5);
explosionAnimation.animations.add('kaboom');
}
var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true);
tween.onComplete.add(descend, this);
cursors = game.input.keyboard.createCursorKeys();
fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
}
@@ -60,16 +75,16 @@ function update() {
player.body.velocity.x = 0;
player.body.velocity.y = 0;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
if (cursors.left.isDown)
{
player.body.velocity.x = -200;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
else if (cursors.right.isDown)
{
player.body.velocity.x = 200;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
if (fireButton.isDown)
{
fireBullet();
}
@@ -104,16 +119,11 @@ function collisionHandler (bullet, alien) {
bullet.kill();
alien.kill();
var explosionAnimation = explosions.getFirstDead();
explosionAnimation.reset(alien.body.x, alien.body.y);
explosionAnimation.play('kaboom', 30, false, true);
}
function render () {
// aliens.forEach(renderBounds, this);
game.debug.renderQuadTree(game.physics.quadTree);
}
function renderBounds(s) {
game.debug.renderSpriteBounds(s, 'rgba(0,0,255,0.4)', true);
}