更改 .x 属性 什么都不做,但是 .body.property 有效
Changing .x property does nothing, but .body.property works
我有一个多人游戏,其中多个客户端拉动一个中心对象。我想在客户端之间同步该对象的位置,例如,如果其中一个切换选项卡一段时间。
这是我的更新功能:
// update velocities of main object to those received from the server
ball.body.velocity.y = game.y;
ball.body.velocity.x = game.x;
// does nothing
ball.x = 600;
// works as expected, pinning ball to x 600
ball.body.x = 600;
为什么会这样?我知道 .x 和 .body.x 应该与精灵上启用的物理相同。
据我所知,.body.x 和 .x 是不同的。根据phaser.io,
All physics operations should be performed against the body rather than the Sprite itself.
因此,如果 sprite 有主体,则使用 .body。当这两个属性在错误的情况下使用时,它根本不起作用,可能是由于物理引擎应用于对象。这是我的使用指南:
在任何启用物理的对象上使用 .body.x,例如精灵、组、平台等。
在任何未启用物理引擎的对象上使用 .x,例如瓷砖精灵、粒子(大多数情况下)、其他与其他对象没有交互的装饰性精灵。
我有一个多人游戏,其中多个客户端拉动一个中心对象。我想在客户端之间同步该对象的位置,例如,如果其中一个切换选项卡一段时间。
这是我的更新功能:
// update velocities of main object to those received from the server
ball.body.velocity.y = game.y;
ball.body.velocity.x = game.x;
// does nothing
ball.x = 600;
// works as expected, pinning ball to x 600
ball.body.x = 600;
为什么会这样?我知道 .x 和 .body.x 应该与精灵上启用的物理相同。
据我所知,.body.x 和 .x 是不同的。根据phaser.io,
All physics operations should be performed against the body rather than the Sprite itself.
因此,如果 sprite 有主体,则使用 .body。当这两个属性在错误的情况下使用时,它根本不起作用,可能是由于物理引擎应用于对象。这是我的使用指南:
在任何启用物理的对象上使用 .body.x,例如精灵、组、平台等。
在任何未启用物理引擎的对象上使用 .x,例如瓷砖精灵、粒子(大多数情况下)、其他与其他对象没有交互的装饰性精灵。