如何防止物体跳出平台?

时间:2017-10-13 14:54:02

标签: javascript phaser-framework

我的游戏设置如下:

INSERT INTO @tmpOptions(CODE_OPTION, PRINT_TEXT)
SELECT data.id.value('CODE_DATA[1]','INT')),
       option.id.value('CODE_OPTION[1]','INT'))
       option.id.value('PRINT_TEXT[1]','VARCHAR(50)'))
FROM @xml.nodes('ROOT_NODE/FOLDER_LIST/FOLDER') as folder(Id)
    CROSS APPLY folder.Id.nodes('DATA_LIST/DATA') as data(Id)
    CROSS APPLY data.Id.nodes('OPTIONS/OPTION') as option(Id)

目前,我可以检查var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {preload: preload, create: create, update: update}); var platforms; var aGroup; function preload() { game.load.image('platform', 'img/platform.png'); game.load.image('a', 'img/a.png'); } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); platforms = game.add.group(); platforms.enableBody = true; var platform = platforms.create(100, 100, 'platform'); aGroup = game.add.group(); aGroup.enableBody = true; platforms.forEach(function(item) { item.body.immovable = true; aGroup.create(item.x, item.y - 32, 'a'); }, this); aGroup.forEach(function(a) { a.body.velocity.x = 100; } } function update() { game.physics.arcade.collide(aGroup, platforms); aGroup.forEach(function(a) { if(a.body.blocked.right) { a.body.velocity.x = -100; } else if(a.body.blocked.left) { a.body.velocity.x = 100; }, this); } } 是否与世界边界发生碰撞,如果发生这种情况,则会改变方向。现在当a到达平台的末端时,它就会掉下来。我希望a在到达平台末端时改变方向。

我该怎么做?

0 个答案:

没有答案