ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.

This commit is contained in:
photonstorm
2013-12-17 16:48:03 +00:00
parent a0961f27df
commit dd7ae12271
13 changed files with 250 additions and 42 deletions
+19 -14
View File
@@ -5,39 +5,44 @@ function preload() {
game.load.image('disk', 'assets/sprites/p2.jpeg');
}
var s;
var tilesprite;
var cursors;
var count = 0;
function create() {
s = game.add.tileSprite(0, 0, 512, 512, 'disk');
tilesprite = game.add.tileSprite(0, 0, 512, 512, 'disk');
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
count += 0.005
s.tileScale.x = 2 + Math.sin(count);
s.tileScale.y = 2 + Math.cos(count);
tilesprite.tileScale.x = 2 + Math.sin(count);
tilesprite.tileScale.y = 2 + Math.cos(count);
s.tilePosition.x += 1;
s.tilePosition.y += 1;
tilesprite.tilePosition.x += 1;
tilesprite.tilePosition.y += 1;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
if (cursors.left.isDown)
{
s.x -= 4;
tilesprite.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
else if (cursors.right.isDown)
{
s.x += 4;
tilesprite.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
if (cursors.up.isDown)
{
s.y -= 4;
tilesprite.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
else if (cursors.down.isDown)
{
s.y += 4;
tilesprite.y += 4;
}
}
@@ -0,0 +1,59 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var ball;
var tilesprite;
var cursors;
function preload() {
game.load.image('starfield', 'assets/misc/starfield.jpg');
game.load.image('ball', 'assets/sprites/pangball.png');
}
function create() {
ball = game.add.sprite(400, 0, 'ball');
ball.body.gravity.y = 6;
ball.body.bounce.y = 1;
tilesprite = game.add.tileSprite(300, 450, 200, 100, 'starfield');
tilesprite.body.immovable = true;
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
game.physics.collide(ball, tilesprite);
if (cursors.left.isDown)
{
tilesprite.x += 8;
tilesprite.tilePosition.x += 8;
}
else if (cursors.right.isDown)
{
tilesprite.x -= 8;
tilesprite.tilePosition.x -= 8;
}
if (cursors.up.isDown)
{
tilesprite.tilePosition.y += 8;
}
else if (cursors.down.isDown)
{
tilesprite.tilePosition.y -= 8;
}
}
function render() {
game.debug.renderSpriteBounds(tilesprite);
}
+17 -10
View File
@@ -1,34 +1,41 @@
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
var s;
var tilesprite;
var cursors;
function preload() {
game.load.image('starfield', 'assets/misc/starfield.jpg');
}
function create() {
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
tilesprite = game.add.tileSprite(0, 0, 800, 600, 'starfield');
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
if (cursors.left.isDown)
{
s.tilePosition.x += 8;
tilesprite.tilePosition.x += 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
else if (cursors.right.isDown)
{
s.tilePosition.x -= 8;
tilesprite.tilePosition.x -= 8;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
if (cursors.up.isDown)
{
s.tilePosition.y += 8;
tilesprite.tilePosition.y += 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
else if (cursors.down.isDown)
{
s.tilePosition.y -= 8;
tilesprite.tilePosition.y -= 8;
}
}