Skip to content

Commit 4cac640

Browse files
committed
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.
1 parent f22af81 commit 4cac640

9 files changed

Lines changed: 626 additions & 184 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Updates:
172172
* Completely empty Tilemaps can now be created. This allows for dynamic map generation at runtime.
173173
* Keyboard.event now stores the most recent DOM keyboard event.
174174
* Animation.stop has a new parameter: dispatchComplete. If true it'll dispatch an Animation.onComplete event.
175+
* TileSprites now have a physics body property and call it in the pre and post updates. As with all physics bodies it's null by default.
175176

176177

177178
Bug Fixes:

examples/wip/ninja aabb vs aabb.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
4+
5+
function preload() {
6+
7+
game.load.image('block', 'assets/sprites/block.png');
8+
9+
}
10+
11+
var sprite1;
12+
var sprite2;
13+
var cursors;
14+
15+
function create() {
16+
17+
game.physics.startSystem(Phaser.Physics.NINJA);
18+
19+
sprite1 = game.add.sprite(100, 100, 'block');
20+
sprite2 = game.add.sprite(400, 100, 'block');
21+
22+
// game.physics.ninja.enableAABB([sprite1]);
23+
game.physics.ninja.enableAABB([sprite1, sprite2]);
24+
25+
cursors = game.input.keyboard.createCursorKeys();
26+
27+
}
28+
29+
function update() {
30+
31+
game.physics.ninja.collide(sprite1, sprite2);
32+
33+
if (cursors.left.isDown)
34+
{
35+
sprite1.body.moveLeft(20);
36+
}
37+
else if (cursors.right.isDown)
38+
{
39+
sprite1.body.moveRight(20);
40+
}
41+
42+
// if (cursors.up.isDown && sprite1.body.touching.down)
43+
if (cursors.up.isDown)
44+
{
45+
// sprite1.body.moveUp(1000);
46+
sprite1.body.moveUp(30);
47+
}
48+
// else if (cursors.down.isDown)
49+
// {
50+
// sprite1.body.moveDown(20);
51+
// }
52+
53+
}
54+
55+
function render() {
56+
57+
game.debug.text('left: ' + sprite1.body.touching.left, 32, 32);
58+
game.debug.text('right: ' + sprite1.body.touching.right, 256, 32);
59+
game.debug.text('up: ' + sprite1.body.touching.up, 32, 64);
60+
game.debug.text('down: ' + sprite1.body.touching.down, 256, 64);
61+
62+
}

examples/wip/ninja tilesprite.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
// var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
4+
5+
function preload() {
6+
7+
game.load.image('starfield', 'assets/misc/starfield.jpg');
8+
game.load.image('ball', 'assets/sprites/shinyball.png');
9+
10+
}
11+
12+
var ball;
13+
var sprite;
14+
var cursors;
15+
16+
function create() {
17+
18+
game.physics.startSystem(Phaser.Physics.NINJA);
19+
20+
sprite = game.add.tileSprite(100, 100, 200, 200, 'starfield');
21+
sprite.autoScroll(0, 100);
22+
23+
game.physics.ninja.enableAABB(sprite);
24+
// game.physics.ninja.enableTile(sprite, 14);
25+
26+
// By default Tiles have gravity and world collision disabled (as they are mostly used for platforms and the likes)
27+
// We re-enable it here
28+
// sprite.body.gravityScale = 1;
29+
// sprite.body.collideWorldBounds = true;
30+
31+
ball = game.add.sprite(400, 0, 'ball');
32+
33+
// Enable the physics body for the Ninja physics system
34+
game.physics.ninja.enableCircle(ball, ball.width / 2);
35+
36+
// A little more bounce
37+
ball.body.bounce = 0.5;
38+
39+
cursors = game.input.keyboard.createCursorKeys();
40+
41+
}
42+
43+
function update() {
44+
45+
game.physics.ninja.collide(sprite, ball);
46+
47+
if (cursors.left.isDown)
48+
{
49+
sprite.body.moveLeft(20);
50+
}
51+
else if (cursors.right.isDown)
52+
{
53+
sprite.body.moveRight(20);
54+
}
55+
56+
if (cursors.up.isDown)
57+
{
58+
sprite.body.moveUp(20);
59+
}
60+
else if (cursors.down.isDown)
61+
{
62+
sprite.body.moveDown(20);
63+
}
64+
65+
}
66+
67+
function render() {
68+
69+
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);
70+
71+
// game.debug.text(sprite.body.x, 32, 32);
72+
// game.debug.text(sprite.body.y, 32, 64);
73+
// game.debug.text(sprite.body.width, 128, 32);
74+
// game.debug.text(sprite.body.height, 128, 64);
75+
// game.debug.geom(r, 'rgba(0,255,0,0.4)', true);
76+
77+
}

examples/wip/ninja3.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var sprite1;
1515
var tiles;
1616
var cursors;
1717

18-
1918
function create() {
2019

2120
var sky = game.add.image(0, 0, 'sky');

0 commit comments

Comments
 (0)