未捕获的TypeError:无法将属性'setCollisionByExclusion'设置为null

时间:2019-11-01 10:25:56

标签: javascript json game-engine

所以我正在尝试使用Phaser 3编写不懂任何JS的游戏

代码是

var map;
var player;
var cursors;
var groundLayer, coinLayer;
var text;
var score = 0;

function preload() {
    this.load.tilemapTiledJSON('map', 'assets/test.json');
    this.load.spritesheet('tiles', 'assets/tiles.png', {frameWidth: 32, frameHeight: 32});
    this.load.atlas('player', 'assets/postac.png', 'assets/postac.json');
}

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

    var groundTiles = map.addTilesetImage('tiles');
    groundLayer = map.createDynamicLayer('World', groundTiles, 0, 0);
    groundLayer.setCollisionByExclusion([1]);

    // set the boundaries of our game world
    this.physics.world.bounds.width = groundLayer.width;
    this.physics.world.bounds.height = groundLayer.height;

    // create the player sprite
    player = this.physics.add.sprite(200, 200, 'player');
    player.setBounce(0.2); // our player will bounce from items
    player.setCollideWorldBounds(true); // don't go out of the map

    this.physics.add.collider(groundLayer, player);

基本上是复制粘贴

以及是否有帮助

我收到“无效的Tilemap图层ID:世界”警告

我尝试将-1更改为1,但这没有帮助

0 个答案:

没有答案