在将tilemap加载到相位器3时遇到问题 [英] having a problem loading a tilemap into phaser 3

查看:66
本文介绍了在将tilemap加载到相位器3时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在加载使用平铺"创建的图块时遇到了问题,我查看了Phaser 3示例,甚至将其文件和png图块图像复制粘贴到我的项目文件夹中,并且可以正常工作,所以很漂亮确保原因是我误用了平铺"软件并且不知道如何正确处理json文件,因此我将添加正在获取的错误和json文件的图像. 注意:我出现黑屏. https://i.stack.imgur.com/dF8ee.png / https://i.stack.imgur.com/E04ng.png

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);
}

推荐答案

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>

这篇关于在将tilemap加载到相位器3时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆