mirror of
https://github.com/wassname/phaser.git
synced 2026-08-11 11:23:06 +08:00
Fixed the Body collide issues and optimised the process at the same time. Now the QuadTree appears to work perfectly as a result. Bonus!
This commit is contained in:
+14
-2
@@ -24,17 +24,29 @@
|
||||
function create() {
|
||||
|
||||
player = game.add.sprite(400, 300, 'ship');
|
||||
player.alpha = 0.2;
|
||||
player.body.collideWorldBounds = true;
|
||||
player.body.bounce.setTo(1, 1);
|
||||
|
||||
// The body offset is from the ANCHOR point of the Sprite, not the top-left (or center, etc)
|
||||
player.body.setSize(60, 60, 0, 0);
|
||||
player.anchor.setTo(0.5, 0.5);
|
||||
player.body.velocity.x = 100;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
// console.log(Math.floor(player.center.x), Math.floor(player.center.y));
|
||||
player.angle++;
|
||||
player.scale.x += 0.005;
|
||||
player.scale.y += 0.005;
|
||||
}
|
||||
|
||||
function render() {
|
||||
game.debug.renderSpriteCorners(player,true,true);
|
||||
game.debug.renderRectangle(player.body.bounds);
|
||||
// game.debug.renderSpriteCorners(player,true,true);
|
||||
game.debug.renderRectangle(player.body);
|
||||
game.debug.renderPixel(400, 300, 'rgb(255,0,0)');
|
||||
game.debug.renderPoint(player.center, 'rgb(255,254,0)');
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
+2
-2
@@ -56,8 +56,8 @@
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteCorners(bunny, true, true);
|
||||
game.debug.renderRectangle(bunny.body.bounds);
|
||||
game.debug.renderRectangle(wall.body.bounds);
|
||||
game.debug.renderRectangle(bunny.body);
|
||||
game.debug.renderRectangle(wall.body);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
function create() {
|
||||
|
||||
player = game.add.sprite(400, 500, 'ship');
|
||||
// player.anchor.setTo(0.5, 0.5);
|
||||
player.anchor.setTo(0.5, 0.5);
|
||||
|
||||
aliens = game.add.group();
|
||||
|
||||
@@ -33,13 +33,14 @@
|
||||
{
|
||||
for (var x = 0; x < 10; x++)
|
||||
{
|
||||
aliens.create(x * 48, y * 64, 'alien');
|
||||
aliens.create(x * 48, y * 50, 'alien');
|
||||
}
|
||||
}
|
||||
|
||||
aliens.x = 100;
|
||||
aliens.y = 50;
|
||||
|
||||
var tween = game.add.tween(aliens).to({x: 200}, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
tween.onComplete.add(descend, this);
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
ship = game.add.sprite(400, 400, 'ship');
|
||||
ship.body.collideWorldBounds = true;
|
||||
ship.body.bounce.setTo(0.5, 0.5);
|
||||
ship.body.bounce.setTo(1, 1);
|
||||
|
||||
}
|
||||
|
||||
@@ -64,14 +64,14 @@
|
||||
}
|
||||
|
||||
game.physics.collideGroup(aliens);
|
||||
// total = game.physics.overlap(ship);
|
||||
total = game.physics.overlap(ship);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderQuadTree(game.physics.quadTree);
|
||||
game.debug.renderRectangle(ship.body.bounds);
|
||||
game.debug.renderRectangle(ship.body);
|
||||
|
||||
// game.debug.renderText('total: ' + total.length, 32, 50);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user