Skip to content

Commit 9c1fdb3

Browse files
committed
Nearly finished Tilemap integration into the core.
1 parent 31018b9 commit 9c1fdb3

8 files changed

Lines changed: 1246 additions & 507 deletions

File tree

build/phaser.js

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

examples/particles/click burst.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
<script type="text/javascript">
77

8-
9-
108
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
119

1210
var emitter;
@@ -44,7 +42,6 @@ function particleBurst() {
4442

4543
}
4644

47-
4845
</script>
4946

5047
<?php

examples/tilemaps/Sci-Fly.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
$title = "Full-screen Tilemap Fly Around";
3+
require('../head.php');
4+
?>
5+
6+
<script type="text/javascript">
7+
8+
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
9+
// var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
10+
11+
function preload() {
12+
13+
game.load.tilemap('level3', 'assets/maps/cybernoid.json', null, Phaser.Tilemap.TILED_JSON);
14+
game.load.tileset('tiles', 'assets/maps/cybernoid.png', 16, 16);
15+
game.load.image('phaser', 'assets/sprites/phaser-ship.png');
16+
game.load.image('diamond', 'assets/sprites/chunk.png');
17+
18+
}
19+
20+
var map;
21+
var tileset;
22+
var layer;
23+
var cursors;
24+
var overlap;
25+
var sprite;
26+
var emitter;
27+
28+
function create() {
29+
30+
game.stage.backgroundColor = '#3d3d3d';
31+
32+
// A Tilemap object just holds the data needed to describe the map (i.e. the json exported from Tiled, or the CSV exported from elsewhere).
33+
// You can add your own data or manipulate the data (swap tiles around, etc) but in order to display it you need to create a TilemapLayer.
34+
map = game.add.tilemap('level3');
35+
36+
// A Tileset is a single image containing a strip of tiles. Each tile is broken down into its own Phaser.Tile object on import.
37+
// You can set properties on the Tile objects, such as collision, n-way movement and meta data.
38+
// A Tilemap uses a Tileset to render. The indexes in the map corresponding to the Tileset indexes.
39+
// This way multiple levels can share the same single Tileset without requiring one each.
40+
tileset = game.add.tileset('tiles');
41+
42+
// Basically this sets EVERY SINGLE tile to fully collide on all faces
43+
tileset.setCollisionRange(0, tileset.total - 1, true, true, true, true);
44+
45+
// And this turns off collision on the only tile we don't want collision on :)
46+
tileset.setCollision(6, false, false, false, false);
47+
tileset.setCollision(31, false, false, false, false);
48+
tileset.setCollision(34, false, false, false, false);
49+
tileset.setCollision(35, false, false, false, false);
50+
tileset.setCollision(46, false, false, false, false);
51+
52+
// A TilemapLayer consists of an x,y coordinate (position), a width and height, a Tileset and a Tilemap which it uses for map data.
53+
// The x/y coordinates are in World space and you can place the tilemap layer anywhere in the world.
54+
// The width/height is the rendered size of the layer in pixels, not the size of the map data itself.
55+
56+
layer = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 0);
57+
58+
layer.resizeWorld();
59+
60+
sprite = game.add.sprite(450, 80, 'phaser');
61+
sprite.anchor.setTo(0.5, 0.5);
62+
63+
game.camera.follow(sprite);
64+
game.camera.deadzone = new Phaser.Rectangle(160, 160, layer.renderWidth-320, layer.renderHeight-320);
65+
66+
cursors = game.input.keyboard.createCursorKeys();
67+
68+
emitter = game.add.emitter(0, 0, 200);
69+
70+
emitter.makeParticles('diamond');
71+
emitter.minRotation = 0;
72+
emitter.maxRotation = 0;
73+
emitter.gravity = 5;
74+
emitter.bounce.setTo(0.5, 0.5);
75+
76+
game.input.onDown.add(particleBurst, this);
77+
78+
}
79+
80+
function particleBurst() {
81+
82+
emitter.x = game.input.worldX;
83+
emitter.y = game.input.worldY;
84+
emitter.start(true, 4000, null, 10);
85+
86+
}
87+
88+
function update() {
89+
90+
game.physics.collide(sprite, layer);
91+
game.physics.collide(emitter, layer);
92+
93+
sprite.body.velocity.x = 0;
94+
sprite.body.velocity.y = 0;
95+
96+
if (cursors.up.isDown)
97+
{
98+
sprite.body.velocity.y = -150;
99+
}
100+
else if (cursors.down.isDown)
101+
{
102+
sprite.body.velocity.y = 150;
103+
}
104+
105+
if (cursors.left.isDown)
106+
{
107+
sprite.body.velocity.x = -150;
108+
sprite.scale.x = -1;
109+
}
110+
else if (cursors.right.isDown)
111+
{
112+
sprite.body.velocity.x = 150;
113+
sprite.scale.x = 1;
114+
}
115+
116+
}
117+
118+
</script>
119+
120+
<?php
121+
require('../foot.php');
122+
?>

0 commit comments

Comments
 (0)