我基本上是在尝试使用 Phaser 创建一个平台游戏。我在 Tiled 中创建了一个 JSON 文件,现在正尝试将它添加到世界中。实际上,过去三个小时我一直在尝试添加它,但没有成功。我看了很多帖子和教程,但没有任何效果。希望有人可以提供帮助?
这是我的html:
<!DOCTYPE html><html>
<head>
<title>Platformer</title>
<script type="text/javascript" src="phaser.js"></script>
<script type="text/javascript" src="Game.js"></script>
</head>
<body>
<div id="gameDiv"></div>
</body>
还有我的 Game.js:
var game = new Phaser.Game(800,600,Phaser.AUTO,"gameDiv",{ preload: preload, create: create, update: update });
function preload() {
game.load.tilemap("map","assets/LvlOneMap.json",null,Phaser.Tilemap.TILED_JSON);
game.load.image("tiles","assets/spritesheet_2.png");
}
var map;
var layer;
function create(){
map = game.add.tilemap("map");
map.addTilesetImage("Tiles","tiles");
layer = map.createLayer("GroundLayer");
layer.resizeWorld();
}
function update() {
//Gameloop
}
这是我的“LvlOneMap.json”文件:
{ "height":10,
"layers":[
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 0, 0, 0, 0, 123, 123, 123, 123, 123, 123, 123, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 0, 0, 0, 0, 153, 153, 155, 155, 155, 155, 155, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 122, 122, 0, 0, 153, 153, 155, 155, 155, 155, 155, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 153, 155, 155, 155, 155, 155, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 153, 153, 155, 155, 155, 155, 155, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, 123, 123, 123, 123, 123, 123, 153, 153, 155, 155, 155, 155, 155, 155, 0, 0, 0, 0, 0, 0, 123, 123, 123, 123, 123, 123, 153, 153, 153, 153, 153, 153, 153, 153, 155, 155, 155, 155, 155, 155, 155, 123, 123, 123, 123, 123, 123, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 155, 155, 155, 155, 155],
"height":10,
"name":"BackgroundLayer",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":27,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":10,
"name":"GroundLayer",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":27,
"x":0,
"y":0
}],
"nextobjectid":1,
"orientation":"orthogonal",
"properties":
{
},
"renderorder":"right-down",
"tileheight":21,
"tilesets":[
{
"firstgid":1,
"image":"spritesheet_2.png",
"imageheight":372,
"imagewidth":694,
"margin":3,
"name":"Tiles",
"properties":
{
},
"spacing":2,
"tilecount":480,
"tileheight":21,
"tilewidth":21,
"transparentcolor":"#4a698c"
}],
"tilewidth":21,
"version":1,
"width":27
}
我还应该注意,图层的名称与 Tiled 中的名称匹配,并且 Tile Layer Format 设置为 CSV。