我有一组“平台”对象和一个“玩家”对象。平台对象应该具有稳定的正y速度,但是当玩家对象与其中一个平台对象发生碰撞时,速度会受到影响并变为负值。任何人都知道如何解决这个问题?
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
var platforms;
var player;
var player1Bullets;
function preload() {
game.load.image('ground', 'assets/platform.png');
game.load.spritesheet('dude', 'assets/doffaSmall.png', 57, 69);
}
var gameOver = false;
var thing;
var roofGroup;
function CreatePlayer(name, x) {
var chara = new APlayer(name, x);
game.physics.arcade.enable(chara.character);
chara.character.body.gravity.y = 20;
chara.character.body.collideWorldBounds = true;
chara.character.animations.add('left', [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], 11, true);
chara.character.animations.add('right', [8, 7, 6, 5, 4, 3, 2, 1, 0], 10, true);
return chara;
}
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
roofGroup = game.add.group();
roofGroup.enableBody = true;
var roof = roofGroup.create(0,0, 'ground');
roof.scale.setTo(2,1);
roof.body.immovable = true;
platforms = game.add.group();
platforms.enableBody = true;
var ledge = platforms.create(100, 500, 'ground');
ledge.scale.setTo(0.5, 0.5);
platforms.addAll('body.velocity.y', -20)
platforms.allowGravity = false;
player = CreatePlayer('per', 96);
player.leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
player.rightKey = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
player.upKey = game.input.keyboard.addKey(Phaser.Keyboard.UP);
player.shootKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.SPACEBAR, Phaser.Keyboard.W, Phaser.Keyboard.A, Phaser.Keyboard.D, Phaser.Keyboard.E ]);
}
function killPlatform (platform, roof) {
platform.kill();
}
function update() {
if(platforms.countLiving() < 4) {
var x = Math.floor((Math.random() * game.world.width) + 1);
var ledge = platforms.create(x, game.world.height, 'ground');
ledge.scale.setTo(0.5,0.5);
platforms.addAll('body.velocity.y', -20);
platforms.allowGravity = false;
}
game.physics.arcade.collide(platforms, roofGroup, killPlatform, null, this);
player.move();
}
答案 0 :(得分:1)
我认为您的意思是:玩家站在地板上,由于碰撞,地板被向下推。如何使其稳定?
floor.body.immovable = true;
这是一个精灵,但您也可以将其应用于组。