我有一种方法可以在 Box2d 中对球施加力。
在桌面上本地测试它工作正常,但在 iPad (ios7) 上,该方法只执行到一半!
我从来没有遇到过这么奇怪的错误,这里有什么问题:
function onTouch(e:TouchEvent) {
var touch:Touch = e.getTouch(this) as Touch;
if (touch && touch.phase == TouchPhase.ENDED) {
//do something
_debugT.text = "works";
var mouseX_m:Number = touch.globalX;
var mouseY_m:Number = touch.globalY;
_debugT.text = "stops here...";
var xDiff:Number = mouseX_m - (_whiteBall.GetPosition().x * WORLD_SCALE);
var yDiff:Number = mouseY_m - (_whiteBall.GetPosition().y * WORLD_SCALE);
var angle:Number = Math.atan2(yDiff, xDiff);
var angleDeg:Number = angle * 180 / Math.PI;
_debugT.text = "never gets executed"
var len = Math.sqrt((xDiff * xDiff) + (yDiff * yDiff));
var vx = len * Math.cos(angle);
var vy = len * Math.sin(angle);
var vel = _whiteBall.GetLinearVelocity();
vel.x += (vx * 5);
vel.y += (vy * 5);
var force = new b2Vec2(vel.x, vel.y);
_whiteBall.SetAwake(vel);
_whiteBall.SetLinearVelocity(force);
}
}