我正在尝试使用phaser-arcade-slopes.min.js插件让sprite在phaser内的斜坡上运行时遇到此问题。我正在使用.csv tilemap,其平铺大小为32x32。我不确定我的名字是不正确还是我正在使用错误类型的文件来处理tilemap本身。我一直在收到错误,比如-Tilemap.createLayer:给出了无效的图层ID:null&无法读取undefined(...)的属性'resizeWorld'。任何帮助将非常感激。 “snow_tiles_32.png”是我创建的tileset的名称,我正在使用它 “tiles.csv”在Tiled内创建的tilemap。
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
this.game.load.tilemap('tilemap', 'assets/tilemaps/csv/tiles.csv', null, Phaser.Tilemap.CSV);
this.game.load.spritesheet('tiles', 'assets/tilemaps/tiles/snow_tiles_32.png', 32,32);
this.game.load.spritesheet('player', 'assets/penguin.png', 32,48);
}
var player;
var cursors;
function create() {
this.game.physics.startSystem(Phaser.Physics.ARCADE);
this.game.plugins.add(Phaser.Plugin.ArcadeSlopes);
cursors = game.input.keyboard.createCursorKeys();
this.map = this.game.add.tilemap('tilemap');
this.map.addTilesetImage('snow_tiles_32', 'tiles');
this.game.stage.backgroundColor = '#80e3ff';
this.ground = this.map.createLayer('collision');
this.ground.resizeWorld();
this.game.slopes.convertTilemapLayer(this.ground,{
2: 'FULL',
3: 'HALF_BOTTOM_LEFT',
4: 'HALF_BOTTOM_RIGHT',
6: 'HALF_TOP_LEFT',
5: 'HALF_TOP_RIGHT',
15: 'QUARTER_BOTTOM_LEFT_LOW',
16: 'QUARTER_BOTTOM_RIGHT_LOW',
17: 'QUARTER_TOP_RIGHT_LOW',
18: 'QUARTER_TOP_LEFT_LOW',
19: 'QUARTER_BOTTOM_LEFT_HIGH',
20: 'QUARTER_BOTTOM_RIGHT_HIGH',
21: 'QUARTER_TOP_RIGHT_HIGH',
22: 'QUARTER_TOP_LEFT_HIGH',
23: 'QUARTER_LEFT_BOTTOM_HIGH',
24: 'QUARTER_RIGHT_BOTTOM_HIGH',
25: 'QUARTER_RIGHT_TOP_LOW',
26: 'QUARTER_LEFT_TOP_LOW',
27: 'QUARTER_LEFT_BOTTOM_LOW',
28: 'QUARTER_RIGHT_BOTTOM_LOW',
29: 'QUARTER_RIGHT_TOP_HIGH',
30: 'QUARTER_LEFT_TOP_HIGH',
31: 'HALF_BOTTOM',
32: 'HALF_RIGHT',
33: 'HALF_TOP',
34: 'HALF_LEFT'
});
this.map.setCollisionBetween(2,34, true, 'collision');
//player
this.player = this.game.add.sprite(100,50,'player');
this.game.physics.arcade.enable(player);
this.player.body.bounce.y = 0.2;
this.player.body.gravity.y = 2000;
this.player.body.collideWorldBounds = true;
this.player.animations.add('left', [0,1,2,3], 10, true);
this.player.animations.add('right', [5,6,7,8], 10, true);
this.game.slopes.enable(this.player);
this.game.camera.follow(this.player);
}
function update() {
this.game.physics.arcade.collide(this.player, this.ground);
this.player.body.velocity.x = 0;
if(cursors.left.isDown){
this.player.body.velocity.x = -150;
this.player.animations.play('left');
}
else if (cursors.right.isDown){
this.player.body.velocity.x = 150;
this.player.animations.play('right');
}
else{
this.player.animations.stop();
this.player.frame = 4;
}
if(cursors.up.isDown && player.body.onFloor()){
this.player.body.velocity.y = -350;
}
}
答案 0 :(得分:0)
您作为createLayer()参数提供的LayerID必须与地图文件中定义的地图图层匹配,请参阅documentation。所以我最好的猜测是再次打开平铺的地图文件并检查你有哪些图层名称。
此外还有一些示例如何使用.csv文件(此处)[http://phaser.io/examples/v2/tilemaps/csv-map]。
希望能以某种方式提供帮助。