精灵坐标我有一个表示子弹及其基本实现一个精灵如下:更新基于其方向
function Bullet(x, y, rotation) {
this.x = x;
this.y = y;
this.direction = rotation;
this.speed = 5;
}
Bullet.prototype.update = function() {
// Move the bullet forward
this.x = Math.sin(this.rotation) * this.speed;
this.x = Math.cos(this.rotation) * this.speed;
}
我想要做的,是在前进的子弹它面对的方向和相对于它的速度。但是,当拨打update()
方法this.x
和this.x
时是NaN
。
如果给出它的x
,y
和rotation
信息,使精灵朝向它所面对的方向移动的正确方法是什么?
尝试推行'VECTOR'类。它会使这件事更容易处理。 – Blender 2013-03-09 21:14:47