【发布时间】:2016-05-25 12:36:00
【问题描述】:
我一直在玩一个精灵,试图让它以我期望的方式扫射 - 末日风格。
所以问题是我可以设置我的精灵的角度,我使用velocityFromRotation 相对于其当前角度向上、向下、向左和向右移动它。
到目前为止,很可爱。
问题是我不能沿对角线移动,也就是说,相对于精灵的角度,我需要能够同时向上和向左移动。
我对每个动作都有一个函数,向上、向下、向左和向右 - 因为所有人都使用velocityFromRotation,所以最近按下的键将覆盖第一个键的移动。
据推测,我也可以简单地为每个对角线创建函数,尽管我不完全确定我将传递给 velocityFromRotation 方法来实现这一点 - 但即使这样有效,它也可能会停止我使用模拟输入类型,因为对角线逻辑将被硬编码。我没有使用模拟输入,但我正在尝试将我的预制件构建为尽可能“插入式”可重复使用。
这是我当前的代码:
Ship.prototype.moveForward = function() {
// Move the player up
this.game.physics.arcade.velocityFromAngle(this.angle - 90, this.speed, this.body.velocity);
}
Ship.prototype.moveBackward = function() {
this.game.physics.arcade.velocityFromAngle(this.angle + 90, this.speed, this.body.velocity);
}
Ship.prototype.bankLeft = function() {
// Move the player left
this.game.physics.arcade.velocityFromAngle(this.angle + 180, this.speed, this.body.velocity);
}
Ship.prototype.bankRight = function() {
// Move the player left
this.game.physics.arcade.velocityFromAngle(this.angle, this.speed, this.body.velocity);
}
【问题讨论】:
标签: javascript game-physics phaser-framework