Phaser.js 如何让竖直的墙壁变得坚固?
Phaser.js how to make vertical walls solid?
我创建了一个有墙的小场景。底壁是实心的。但是左和右不是。为什么?你能帮帮我吗?
Game Scene
如你所见,我可以站在底墙上。它很结实。马里奥没有倒下。
但我可以穿过左边或右边的墙。我不知道是什么问题,因为所有这些墙都在同一组中。
所以我也看到当你试图从地面穿过左边的墙时 - 你可以做到。
但是当你想从顶部做同样的事情时,我的意思是掉到墙的顶部 - 你不能那样做。
那么如何使那些墙(左右)坚固而不从地面穿过?
create: function()
{
game.physics.startSystem(Phaser.Physics.ARCADE);
game.stage.backgroundColor = "3984db";
game.physics.arcade.gravity.y = 1200;
this.cursor = game.input.keyboard.createCursorKeys();
this.mario = game.add.sprite((game.width / 2) + 77, game.height / 2, 'mario');
this.mario.anchor.setTo(0.5,0.5);
this.mario.scale.setTo(0.15,0.15);
this.walls = game.add.group();
this.walls.enableBody = true;
this.walls.enableBody = true;
this.spaceBar = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
this.downWallH = game.add.sprite(0, 540, 'WallH', 0, this.walls);
this.UpWallH = game.add.sprite(0, 0, 'WallH', 0, this.walls);
this.leftWallW = game.add.sprite(0,0, 'WallW', 0, this.walls);
this.rightWallW = game.add.sprite(870,0, 'WallW', 0, this.walls);
this.enemy = game.add.sprite(300,300, 'enemy');
this.enemy.scale.setTo(0.2,0.2);
game.physics.arcade.enable([this.mario, this.enemy]);
this.walls.setAll('body.allowGravity', false);
this.walls.setAll('body.immovable', true);
},
我创建了一个有墙的小场景。底壁是实心的。但是左和右不是。为什么?你能帮帮我吗?
Game Scene
如你所见,我可以站在底墙上。它很结实。马里奥没有倒下。 但我可以穿过左边或右边的墙。我不知道是什么问题,因为所有这些墙都在同一组中。
所以我也看到当你试图从地面穿过左边的墙时 - 你可以做到。 但是当你想从顶部做同样的事情时,我的意思是掉到墙的顶部 - 你不能那样做。
那么如何使那些墙(左右)坚固而不从地面穿过?
create: function()
{
game.physics.startSystem(Phaser.Physics.ARCADE);
game.stage.backgroundColor = "3984db";
game.physics.arcade.gravity.y = 1200;
this.cursor = game.input.keyboard.createCursorKeys();
this.mario = game.add.sprite((game.width / 2) + 77, game.height / 2, 'mario');
this.mario.anchor.setTo(0.5,0.5);
this.mario.scale.setTo(0.15,0.15);
this.walls = game.add.group();
this.walls.enableBody = true;
this.walls.enableBody = true;
this.spaceBar = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
this.downWallH = game.add.sprite(0, 540, 'WallH', 0, this.walls);
this.UpWallH = game.add.sprite(0, 0, 'WallH', 0, this.walls);
this.leftWallW = game.add.sprite(0,0, 'WallW', 0, this.walls);
this.rightWallW = game.add.sprite(870,0, 'WallW', 0, this.walls);
this.enemy = game.add.sprite(300,300, 'enemy');
this.enemy.scale.setTo(0.2,0.2);
game.physics.arcade.enable([this.mario, this.enemy]);
this.walls.setAll('body.allowGravity', false);
this.walls.setAll('body.immovable', true);
},