having a problem loading a tilemap into phaser 3

2019-08-27 19:21发布

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条回答
Evening l夕情丶
2楼-- · 2019-08-27 19:56

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>

查看更多
登录 后发表回答