2013-10-22 02:58:20 +00:00
|
|
|
|
2014-01-28 01:29:35 +00:00
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
2013-10-22 02:58:20 +00:00
|
|
|
|
|
|
|
function preload() {
|
|
|
|
|
|
|
|
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
|
|
|
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var sprite1;
|
|
|
|
var sprite2;
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
game.stage.backgroundColor = '#2d2d2d';
|
|
|
|
|
|
|
|
// This will check Sprite vs. Sprite collision
|
|
|
|
|
|
|
|
sprite1 = game.add.sprite(50, 200, 'atari');
|
|
|
|
sprite1.name = 'atari';
|
|
|
|
sprite1.body.velocity.x = 100;
|
|
|
|
|
|
|
|
sprite2 = game.add.sprite(700, 220, 'mushroom');
|
|
|
|
sprite2.name = 'mushroom';
|
|
|
|
sprite2.body.velocity.x = -100;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
|
|
|
// object1, object2, collideCallback, processCallback, callbackContext
|
|
|
|
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function collisionHandler (obj1, obj2) {
|
|
|
|
|
2014-01-14 02:43:09 +00:00
|
|
|
// The two sprites are colliding
|
2013-10-22 02:58:20 +00:00
|
|
|
game.stage.backgroundColor = '#992d2d';
|
|
|
|
|
|
|
|
}
|
2014-01-28 01:29:35 +00:00
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
2014-01-28 06:52:56 +00:00
|
|
|
game.debug.renderPhysicsBody(sprite1.body);
|
|
|
|
game.debug.renderPhysicsBody(sprite2.body);
|
2014-01-28 01:29:35 +00:00
|
|
|
|
|
|
|
}
|