mirror of
https://github.com/wassname/phaser.git
synced 2026-08-14 12:40:17 +08:00
Ninja.AABB updated with all the correct properties, now works fully as with Circle. Created new tests, all Ninja shapes now set Body.touching values correctly. TileSprites work as bodies. Trying out AABB vs. AABB collision now.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
|
||||
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('block', 'assets/sprites/block.png');
|
||||
|
||||
}
|
||||
|
||||
var sprite1;
|
||||
var sprite2;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
game.physics.startSystem(Phaser.Physics.NINJA);
|
||||
|
||||
sprite1 = game.add.sprite(100, 100, 'block');
|
||||
sprite2 = game.add.sprite(400, 100, 'block');
|
||||
|
||||
// game.physics.ninja.enableAABB([sprite1]);
|
||||
game.physics.ninja.enableAABB([sprite1, sprite2]);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.ninja.collide(sprite1, sprite2);
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
sprite1.body.moveLeft(20);
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
sprite1.body.moveRight(20);
|
||||
}
|
||||
|
||||
// if (cursors.up.isDown && sprite1.body.touching.down)
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
// sprite1.body.moveUp(1000);
|
||||
sprite1.body.moveUp(30);
|
||||
}
|
||||
// else if (cursors.down.isDown)
|
||||
// {
|
||||
// sprite1.body.moveDown(20);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.text('left: ' + sprite1.body.touching.left, 32, 32);
|
||||
game.debug.text('right: ' + sprite1.body.touching.right, 256, 32);
|
||||
game.debug.text('up: ' + sprite1.body.touching.up, 32, 64);
|
||||
game.debug.text('down: ' + sprite1.body.touching.down, 256, 64);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
||||
game.load.image('ball', 'assets/sprites/shinyball.png');
|
||||
|
||||
}
|
||||
|
||||
var ball;
|
||||
var sprite;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
game.physics.startSystem(Phaser.Physics.NINJA);
|
||||
|
||||
sprite = game.add.tileSprite(100, 100, 200, 200, 'starfield');
|
||||
sprite.autoScroll(0, 100);
|
||||
|
||||
game.physics.ninja.enableAABB(sprite);
|
||||
// game.physics.ninja.enableTile(sprite, 14);
|
||||
|
||||
// By default Tiles have gravity and world collision disabled (as they are mostly used for platforms and the likes)
|
||||
// We re-enable it here
|
||||
// sprite.body.gravityScale = 1;
|
||||
// sprite.body.collideWorldBounds = true;
|
||||
|
||||
ball = game.add.sprite(400, 0, 'ball');
|
||||
|
||||
// Enable the physics body for the Ninja physics system
|
||||
game.physics.ninja.enableCircle(ball, ball.width / 2);
|
||||
|
||||
// A little more bounce
|
||||
ball.body.bounce = 0.5;
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
game.physics.ninja.collide(sprite, ball);
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
sprite.body.moveLeft(20);
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
sprite.body.moveRight(20);
|
||||
}
|
||||
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
sprite.body.moveUp(20);
|
||||
}
|
||||
else if (cursors.down.isDown)
|
||||
{
|
||||
sprite.body.moveDown(20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
var r = new Phaser.Rectangle(sprite.body.x - (sprite.body.width / 2), sprite.body.y - (sprite.body.height / 2), sprite.body.width, sprite.body.height);
|
||||
|
||||
// game.debug.text(sprite.body.x, 32, 32);
|
||||
// game.debug.text(sprite.body.y, 32, 64);
|
||||
// game.debug.text(sprite.body.width, 128, 32);
|
||||
// game.debug.text(sprite.body.height, 128, 64);
|
||||
// game.debug.geom(r, 'rgba(0,255,0,0.4)', true);
|
||||
|
||||
}
|
||||
@@ -15,7 +15,6 @@ var sprite1;
|
||||
var tiles;
|
||||
var cursors;
|
||||
|
||||
|
||||
function create() {
|
||||
|
||||
var sky = game.add.image(0, 0, 'sky');
|
||||
|
||||
Reference in New Issue
Block a user