【发布时间】:2016-12-11 00:37:53
【问题描述】:
我一直在尝试将一个瓦片地图加载到我从 Tiled 导出为 JSON 的 Phaser 中,但是当我添加它时它一直导致以下错误:
我尝试复制 Phaser 示例并更改字符串以匹配我的文件,以查看是否是我做错了 - 仍然没有工作。
代码:
window.onload = function() {
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phasergame', {preload: preload, create: create, update: update, render: render });
var map;
var layer;
function preload() {
game.load.tilemap('map', 'assets/tilemap/maze.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('tiles', 'assets/tilemap/tiles.png');
}
function create() {
map = game.add.tilemap('map');
map.addTilesetImage('tiles',tiles);
layer = map.createLayer('Walls');
layer.resizeWorld();
}
function update() {}
function render() {}
};
body {
background: black;
margin: 0;
padding: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.js"></script>
我来自 Tiled 的 maze.json:https://gist.github.com/spideynn/efe8e787031ffae89ddb354db129fb53
我的tiles.png:http://i.imgur.com/8cw9DcC.png
【问题讨论】:
标签: javascript phaser-framework