gpt4 book ai didi

javascript - 使用街机物理功能时,斜坡在 Phaser 中不起作用

转载 作者:行者123 更新时间:2023-11-28 05:28:59 24 4
gpt4 key购买 nike

当我尝试使用 Phaser-arcade-slopes.min.js 插件让 Sprite 在 Phaser 内爬上斜坡时,我目前遇到了这个问题。我使用的 .csv 图 block map 的图 block 大小也为 32x32。我不确定我的名字是否不正确,或者我为瓦片 map 本身使用了错误的文件类型。我一直收到错误,例如 - Tilemap.createLayer:给定的图层 ID 无效:null & 无法读取未定义(…)的属性“resizeWorld”。任何帮助将非常感激。“snow_tiles_32.png”是我创建并正在使用的图 block 集的名称“tiles.csv”在 Tiled 中创建的图 block map 。

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

}

最佳答案

作为 createLayer() 参数提供的 LayerID 必须与 map 文件中定义的 map 图层匹配,请参阅 documentation 。所以我最好的猜测是再次打开平铺的 map 文件并检查您拥有的图层名称。

此外,还有如何使用 .csv 文件的示例(此处)[ http://phaser.io/examples/v2/tilemaps/csv-map] .

希望这能有所帮助。

关于javascript - 使用街机物理功能时,斜坡在 Phaser 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39882088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com