Skip to content

Commit 7c8fb70

Browse files
committed
Merge pull request phaserjs#556 from alvinsight/1.2
New examples for ninja physics, bitmap text, and documented the map func
2 parents 181ef7c + c9f89f5 commit 7c8fb70

9 files changed

Lines changed: 1513 additions & 512 deletions

File tree

build/phaser.js

Lines changed: 1070 additions & 494 deletions
Large diffs are not rendered by default.

examples/_site/examples.json

Lines changed: 104 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,6 @@
134134
"file": "quadtree+-+collision+infos.js",
135135
"title": "quadtree - collision infos"
136136
},
137-
{
138-
"file": "quadtree+-+ids.js",
139-
"title": "quadtree - ids"
140-
},
141-
{
142-
"file": "rotated+bounding+box.js",
143-
"title": "rotated bounding box"
144-
},
145137
{
146138
"file": "ship+trail.js",
147139
"title": "ship trail"
@@ -154,10 +146,6 @@
154146
"file": "snake.js",
155147
"title": "snake"
156148
},
157-
{
158-
"file": "sprite+bounds.js",
159-
"title": "sprite bounds"
160-
},
161149
{
162150
"file": "sprite+vs+group.js",
163151
"title": "sprite vs group"
@@ -446,6 +434,10 @@
446434
"file": "for+each.js",
447435
"title": "for each"
448436
},
437+
{
438+
"file": "get+first+dead.js",
439+
"title": "get first dead"
440+
},
449441
{
450442
"file": "get+first.js",
451443
"title": "get first"
@@ -657,6 +649,82 @@
657649
"title": "repeatable random numbers"
658650
}
659651
],
652+
"ninja physics": [
653+
{
654+
"file": "ninja+aabb+vs+aabb.js",
655+
"title": "ninja aabb vs aabb"
656+
},
657+
{
658+
"file": "ninja+aabb+vs+tile.js",
659+
"title": "ninja aabb vs tile"
660+
},
661+
{
662+
"file": "ninja+impact.js",
663+
"title": "ninja impact"
664+
},
665+
{
666+
"file": "ninja+tilemap.js",
667+
"title": "ninja tilemap"
668+
}
669+
],
670+
"p2 physics": [
671+
{
672+
"file": "basic+movement.js",
673+
"title": "basic movement"
674+
},
675+
{
676+
"file": "body+click.js",
677+
"title": "body click"
678+
},
679+
{
680+
"file": "collision+groups.js",
681+
"title": "collision groups"
682+
},
683+
{
684+
"file": "contact+events.js",
685+
"title": "contact events"
686+
},
687+
{
688+
"file": "distance+constraint.js",
689+
"title": "distance constraint"
690+
},
691+
{
692+
"file": "gear+constraint.js",
693+
"title": "gear constraint"
694+
},
695+
{
696+
"file": "gravity.js",
697+
"title": "gravity"
698+
},
699+
{
700+
"file": "impact+events.js",
701+
"title": "impact events"
702+
},
703+
{
704+
"file": "load+polygon+1.js",
705+
"title": "load polygon 1"
706+
},
707+
{
708+
"file": "load+polygon+2.js",
709+
"title": "load polygon 2"
710+
},
711+
{
712+
"file": "postbroadphase+callback.js",
713+
"title": "postbroadphase callback"
714+
},
715+
{
716+
"file": "springs.js",
717+
"title": "springs"
718+
},
719+
{
720+
"file": "thrust.js",
721+
"title": "thrust"
722+
},
723+
{
724+
"file": "world+move.js",
725+
"title": "world move"
726+
}
727+
],
660728
"particles": [
661729
{
662730
"file": "click+burst.js",
@@ -762,6 +830,14 @@
762830
"file": "bitmap+fonts.js",
763831
"title": "bitmap fonts"
764832
},
833+
{
834+
"file": "bitmapfont+drag.js",
835+
"title": "bitmapfont drag"
836+
},
837+
{
838+
"file": "dynamic+text+shadow.js",
839+
"title": "dynamic text shadow"
840+
},
765841
{
766842
"file": "google+webfonts.js",
767843
"title": "google webfonts"
@@ -790,6 +866,22 @@
790866
"file": "retro+font+2.js",
791867
"title": "retro font 2"
792868
},
869+
{
870+
"file": "set+properties+after+creation.js",
871+
"title": "set properties after creation"
872+
},
873+
{
874+
"file": "text+gradient.js",
875+
"title": "text gradient"
876+
},
877+
{
878+
"file": "text+reflect.js",
879+
"title": "text reflect"
880+
},
881+
{
882+
"file": "text+shadow.js",
883+
"title": "text shadow"
884+
},
793885
{
794886
"file": "text+stroke.js",
795887
"title": "text stroke"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
game.load.spritesheet('ninja-tiles', 'assets/physics/ninja-tiles128.png', 128, 128, 34);
9+
10+
}
11+
12+
var sprite1;
13+
var sprite2;
14+
var tile;
15+
var cursors;
16+
17+
18+
function create() {
19+
20+
game.physics.startSystem(Phaser.Physics.NINJA);
21+
22+
sprite1 = game.add.sprite(100, 450, 'block');
23+
sprite1.name = 'blockA';
24+
25+
sprite2 = game.add.sprite(600, 450, 'block');
26+
sprite2.name = 'blockB';
27+
sprite2.tint = Math.random() * 0xffffff;
28+
29+
game.physics.ninja.enableAABB([sprite1, sprite2]);
30+
31+
cursors = game.input.keyboard.createCursorKeys();
32+
33+
}
34+
35+
36+
function update() {
37+
38+
game.physics.ninja.collide(sprite1, sprite2);
39+
40+
41+
if (cursors.left.isDown)
42+
{
43+
sprite1.body.moveLeft(20);
44+
}
45+
else if (cursors.right.isDown)
46+
{
47+
sprite1.body.moveRight(20);
48+
}
49+
50+
if (cursors.up.isDown)
51+
{
52+
sprite1.body.moveUp(30);
53+
}
54+
55+
}
56+
57+
function render() {
58+
59+
game.debug.text('left: ' + sprite1.body.touching.left, 32, 32);
60+
game.debug.text('right: ' + sprite1.body.touching.right, 256, 32);
61+
game.debug.text('up: ' + sprite1.body.touching.up, 32, 64);
62+
game.debug.text('down: ' + sprite1.body.touching.down, 256, 64);
63+
64+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
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+
game.load.spritesheet('ninja-tiles', 'assets/physics/ninja-tiles128.png', 128, 128, 34);
9+
10+
}
11+
12+
var sprite1;
13+
var sprite2;
14+
var tile;
15+
var cursors;
16+
17+
function create() {
18+
19+
// Here we tell the physics manager we system we want to use
20+
game.physics.startSystem(Phaser.Physics.NINJA);
21+
22+
23+
24+
sprite1 = game.add.sprite(600, 100, 'block');
25+
sprite1.name = 'blockA';
26+
27+
// Enable ninja on the sprite and creates an AABB around it
28+
game.physics.ninja.enableAABB(sprite1);
29+
30+
//
31+
tile = game.add.sprite(600, 480, 'ninja-tiles', 3);
32+
game.physics.ninja.enableTile(tile, tile.frame);
33+
34+
cursors = game.input.keyboard.createCursorKeys();
35+
36+
}
37+
38+
function update() {
39+
40+
game.physics.ninja.collide(sprite1, tile);
41+
42+
43+
44+
if (cursors.left.isDown)
45+
{
46+
sprite1.body.moveLeft(20);
47+
}
48+
else if (cursors.right.isDown)
49+
{
50+
sprite1.body.moveRight(20);
51+
}
52+
53+
if (cursors.up.isDown)
54+
{
55+
56+
sprite1.body.moveUp(30);
57+
}
58+
59+
}
60+
61+
function render() {
62+
63+
game.debug.text('left: ' + sprite1.body.touching.left, 32, 32);
64+
game.debug.text('right: ' + sprite1.body.touching.right, 256, 32);
65+
game.debug.text('up: ' + sprite1.body.touching.up, 32, 64);
66+
game.debug.text('down: ' + sprite1.body.touching.down, 256, 64);
67+
68+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update});
3+
4+
function preload() {
5+
6+
game.load.spritesheet('ninja-tiles', 'assets/physics/ninja-tiles128.png', 128, 128, 34);
7+
game.load.image('a', 'assets/sprites/firstaid.png');
8+
9+
}
10+
11+
var sprite1;
12+
var cursors;
13+
14+
var tile1;
15+
var tile2;
16+
17+
18+
19+
function create() {
20+
21+
game.stage.smoothed = true;
22+
23+
// Activate the Ninja physics system
24+
game.physics.startSystem(Phaser.Physics.NINJA);
25+
26+
// game.physics.ninja.gravity = 0.1;
27+
28+
sprite1 = game.add.sprite(500, 200, 'a');
29+
30+
// Enable the physics body for the Ninja physics system
31+
// By default it will create an AABB body for the sprite
32+
game.physics.ninja.enableAABB(sprite1);
33+
34+
// But you can change it to either a Tile or a Circle
35+
tile1 = game.add.sprite(0, 500, 'ninja-tiles', 14);
36+
tile1.width = 100;
37+
tile1.height = 100;
38+
39+
game.physics.ninja.enableTile(tile1, tile1.frame);
40+
41+
cursors = game.input.keyboard.createCursorKeys();
42+
43+
}
44+
45+
function collisionHandler() {
46+
game.stage.backgroundColor = 0xff0000;
47+
}
48+
49+
function update() {
50+
51+
game.physics.ninja.collide(sprite1, tile1, collisionHandler, null, this);
52+
53+
tile1.body.moveRight(1);
54+
55+
if (cursors.left.isDown)
56+
{
57+
sprite1.body.moveLeft(20);
58+
}
59+
else if (cursors.right.isDown)
60+
{
61+
sprite1.body.moveRight(20);
62+
}
63+
64+
if (cursors.up.isDown)
65+
{
66+
sprite1.body.moveUp(20);
67+
}
68+
else if (cursors.down.isDown)
69+
{
70+
sprite1.body.moveUp(20);
71+
}
72+
73+
}

0 commit comments

Comments
 (0)