我正在运行ubuntu 14.04 with Phaser(v2.3.0“Tarabon” - Built:Thu Mar 26 2015 02:36:37)。
我正在尝试使用两个精灵,其中一个(yellowRectangle
)应该被修复而另一个(redSquare
)朝着固定的精灵移动。
问题是当两个精灵碰撞时,应该修复的精灵仍会移动。
我尝试了解决方法来设置yellowRectangle.physicsType = Phaser.SPRITE;
但它没有帮助。
这是一个简短的程序:
var game = new Phaser.Game(width="100", height="100", Phaser.AUTO,'pressIt', { preload: preload, create: create, update:update });
var redSquare; var yellowRectangle;
function preload() {
game.load.image('redSquare', '/redSquare25x25.png');
game.load.image('yellowRectangle', '/yellowRectangle100x10.png');
}
function create() {
game.physics.startSystem(Phaser.Physics.P2JS);
redSquare = game.add.sprite(x=game.world.centerX, y=35, 'redSquare');
game.physics.p2.enable(redSquare);
yellowRectangle = game.add.sprite(x=game.world.centerX, y=game.world.height - 100, 'yellowRectangle');
//was suggested to add due to bug in Phaser, but does not fix it
//yellowRectangle.physicsType = Phaser.SPRITE;
game.physics.p2.enable(yellowRectangle);
yellowRectangle.body.moves = false;
yellowRectangle.immovable = true;
};
function update() {
redSquare.body.force.y = 500;
};
答案 0 :(得分:1)
您应该将黄色矩形设置为不可移动,如下所示:
yellowRectangle.body.immovable = true;
你刚忘了body
部分;)
希望它有所帮助!