having a problem loading a tilemap into phaser 3

对着背影说爱祢 提交于 2020-04-30 10:01:44

问题


I've been having a problem loading a tilemap that I created with "tiled", I looked up the phaser 3 examples, I even copied pasted their file and png tile image into my project folder and it worked, so am pretty sure that the reason is me misusing the "tiled" software and not knowing how to properley handle a json file, I will add images of the errors am getting and the json file. Note: I get a black screen. https://i.stack.imgur.com/dF8ee.png / https://i.stack.imgur.com/E04ng.png

function preload ()
{
this.load.image('tilesplatform', 'ground_1x1.png'); this.load.tilemapTiledJSON('map', 'scene.json'); 
}

function create ()
{

var map = this.make.tilemap({ key: 'map' });
var Ground = map.addTilesetImage('ground_1x1', 'tilesplatform');
map.createStaticLayer(0, ground_1x1, 0, 0);
}

回答1:


var config = {
    type: Phaser.WEBGL,
    width: 400,
    height: 288,
    parent: 'phaser-example',
    loader: {
      baseURL: 'https://raw.githubusercontent.com/nazimboudeffa/assets/master/maps/',
      crossOrigin: 'anonymous'
    },
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);
var map;
var cursors;
var player;
var groundLayer;

function preload ()
{
    this.load.image('tileset', 'sunny-land/tileset.png');
    this.load.tilemapTiledJSON('map', 'sunny-land/level0.json');
}

function create ()
{
  map = this.make.tilemap({ key: 'map' });
  var groundTiles = map.addTilesetImage('tileset');

  map.createStaticLayer('ground', groundTiles, 0, 0);
  //map.createStaticLayer('jumpThrough', groundTiles, 0, 0);

}
<script src="//cdn.jsdelivr.net/npm/phaser@3.17.0/dist/phaser.min.js"></script>


来源:https://stackoverflow.com/questions/56310372/having-a-problem-loading-a-tilemap-into-phaser-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!