Javascript 未捕获类型错误:无法设置属性';通过排除设置冲突';空的
所以我试着用Phaser3编写一个不知道任何JS的游戏 代码是Javascript 未捕获类型错误:无法设置属性';通过排除设置冲突';空的,javascript,json,game-engine,Javascript,Json,Game Engine,所以我试着用Phaser3编写一个不知道任何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.p
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:World”警告
我尝试将-1改为1,但没有任何帮助这意味着
groundLayer中的groundLayer
。setCollisionByExclusion([1])
为null
。您提到的错误表明这是因为map.createDynamicLayer('World',groundTiles,0,0)
失败。缩进减少