Enter Frame 在补间时无法精确检测 hitTestObject
我有一个运行 Enter_Frame 的函数,并在该函数期间对其进行补间。我知道你可以使用 object.y=object.y + 1 而不是我现在使用的 TweenLite。但 TweenLite 给出了我想要的最佳效果。我现在的问题是,我想在相互不碰撞时删除 Enter_frame 函数。但是当我跟踪 hitTestObject 时,hitTestObject 结果立即返回“false”。因此,补间无法真正完成第一,并在对象仍在碰撞时提前删除 Enter_frame 运行。
private function checkCollision (e:Event):void
{
//detect collision in array
for (var j:uint = 0; j < collisionArray.length - 1; j++)
{
for (var k:uint = j + 1; k < collisionArray.length; k++)
{
if (collisionArray[j].hitTestObject(collisionArray[k]))
{
//do something
TweenLite.to (objectA,0.2,{y:move2Y});
TweenLite.to (objectB,0.2,{y:move3Y});
}
trace (collisionArray[j].hitTestObject(collisionArray[k]));
}
}
}
I have a function with Enter_Frame running and have it tween during the function. I know you could use object.y=object.y + 1 instead of the TweenLite i'm using now. But TweenLite gives the best effect I wanted. My problem now is, I wanted to remove the enter_frame function when its not collision each other. But when I traced hitTestObject, it have like a split second where the hitTestObject result return 'false'. So the tweening can't really finish 1st, and remove enter_frame run early while the object is still collisioning.
private function checkCollision (e:Event):void
{
//detect collision in array
for (var j:uint = 0; j < collisionArray.length - 1; j++)
{
for (var k:uint = j + 1; k < collisionArray.length; k++)
{
if (collisionArray[j].hitTestObject(collisionArray[k]))
{
//do something
TweenLite.to (objectA,0.2,{y:move2Y});
TweenLite.to (objectB,0.2,{y:move3Y});
}
trace (collisionArray[j].hitTestObject(collisionArray[k]));
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是,补间直到调用 checkCollision 方法后 0.2 秒才完成。
如果您在 ENTER_FRAME 中调用此方法,您将不断覆盖现有的补间。想想看 - ENTER_FRAME 调用 checkCollisions,checkCollisions 将启动一些补间,在补间有时间完成之前,下一个 ENTER_FRAME 触发,再次调用 checkCollisions 并在同一对象上启动补间,因为补间尚未完成重新定位对象尚未。
您最好的选择可能是根本不使用 ENTER_FRAME - 运行 checkCollisions,为相交对象启动补间,如果存在相交对象,则 0.2 秒后再次调用 chechCollisions(补间完成后)
Your problem is that the tweens don't finish until 0.2 secs after the checkCollision method is called.
If you are calling this method in ENTER_FRAME, you will constantly be overwriting existing tweens. Just think about it - ENTER_FRAME calls checkCollisions, checkCollisions will start some tweens, before the tweens have time to complete, the next ENTER_FRAME fires, calls checkCollisions again and starts tweens on the same objects, since the tweens haven't finished re-positioning the objects yet.
Your best bet might be to not use ENTER_FRAME at all - run checkCollisions, start tweens for intersecting objects, if there are intersecting objects then call chechCollisions again 0.2 seconds later (once the tweens finished)