Promoted the Tilemap to a DisplayObject and vastly simplified the load process.

This commit is contained in:
Richard Davey
2013-09-12 04:24:01 +01:00
parent 3d22d0e169
commit dbaf7269e9
10 changed files with 541 additions and 397 deletions
+2 -20
View File
@@ -16,38 +16,20 @@
function preload() {
// First we load our map data (a csv file)
game.load.text('marioMap', 'assets/maps/mario1.json');
// Then we load the actual tile sheet image
game.load.image('marioTiles', 'assets/maps/mario1.png');
game.load.tilemap('mario', 'assets/maps/mario1.png', 'assets/maps/mario1.json', null, Phaser.Tilemap.JSON);
}
var r;
var t;
function create() {
game.stage.backgroundColor = '#787878';
// game, key, mapData, format, resizeWorld, tileWidth, tileHeight
// This creates the tilemap using the csv and tile sheet we loaded.
// We tell it use to CSV format parser. The 16x16 are the tile sizes.
// The 4th parameter (true) tells the game world to resize itself based on the map dimensions or not.
t = new Phaser.Tilemap(game, 'marioTiles', 'marioMap', Phaser.Tilemap.FORMAT_TILED_JSON);
// SHould be added to the World and rendered automatically :)
r = new Phaser.TilemapRenderer(game);
game.add.tilemap(0, 0, 'mario');
}
function update() {
r.render(t);
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 8;