mirror of
https://github.com/wassname/phaser.git
synced 2026-07-01 16:50:43 +08:00
011d2d8e05
The World level quadtree is no longer created, they are now built and ripped down each time you collide a Group, this helps collision accuracy. Bodies are no longer added to a world quadtree, so have had all of their quadtree properties removed such as skipQuadtree, quadTreeIndex, etc. QuadTree.populate - you can pass it a Group and it'll automatically insert all of the children ready for inspection. Removed ArcadePhysics binding to the QuadTree, so it can now be used independantly of the physics system.
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
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';
|
|
|
|
sprite1 = game.add.sprite(300, 50, 'atari');
|
|
sprite1.name = 'atari';
|
|
sprite1.body.velocity.y = 100;
|
|
|
|
// This adjusts the collision body size.
|
|
// 220x10 is the new width/height.
|
|
// See the offset bounding box for another example.
|
|
sprite1.body.setSize(220, 10, 0, 0);
|
|
|
|
sprite2 = game.add.sprite(400, 450, 'mushroom');
|
|
sprite2.name = 'mushroom';
|
|
sprite2.body.immovable = true;
|
|
|
|
}
|
|
|
|
function update() {
|
|
|
|
// object1, object2, collideCallback, processCallback, callbackContext
|
|
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
|
|
|
}
|
|
|
|
function collisionHandler (obj1, obj2) {
|
|
|
|
game.stage.backgroundColor = '#992d2d';
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
game.debug.renderSpriteInfo(sprite1, 32, 32);
|
|
game.debug.renderSpriteCollision(sprite1, 400, 32);
|
|
|
|
game.debug.renderSpriteBody(sprite1);
|
|
game.debug.renderSpriteBody(sprite2);
|
|
|
|
}
|