我有一个储罐,其嵌套的MovieClip称为桶。
桶成功面对玩家,除非坦克本身旋转。
因此,它仅在油箱不旋转时起作用。
我需要找到一种使旋转起作用的方法,然后我搜索并找到了:
var rot:Number = rotation, p:DisplayObjectContainer = parent, s:DisplayObjectContainer = stage;
while (p != s) {
rot += p.rotation;
p = p.parent;
}
,但我不知道如何在我当前的代码中实现这一点:
// calculate rotation based on target
_dx = this.x - _root.hero.x;
_dy = this.y - _root.hero.y;
// which way to rotate
_rotateTo = getDegrees(getRadians(_dx, _dy));
// keep rotation positive, between 0 and 360 degrees
if (_rotateTo > barrel.rotation + 90) _rotateTo -= 360;
if (_rotateTo < barrel.rotation - 90) _rotateTo += 360;
// ease rotation
_trueRotation = (_rotateTo - barrel.rotation) / _rotateSpeedMax;
//barrel rotation
barrel.rotation += _trueRotation;
我尝试更改
barrel.rotation += _trueRotation;
to
barrel.rotation += _trueRotation + parent.rotation
在网上阅读后,您可以简单地添加所有轮换,但似乎不起作用。
我如何实现
var rot:Number = rotation, p:DisplayObjectContainer = parent, s:DisplayObjectContainer = stage;
while (p != s) {
rot += p.rotation;
p = p.parent;
}
进入我的代码?
您必须否定父的旋转,因此您只能将+=
更改为-=
。
rot -= p.rotation;