mirror of
https://github.com/wassname/phaser.git
synced 2026-08-06 13:31:05 +08:00
Promoted the Tilemap to a DisplayObject and vastly simplified the load process.
This commit is contained in:
+2
-20
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user