我无法让我的动画与过渡正常工作。
我对 Corona 还比较陌生,仍然不确定我是否理解 transition.to
,所以请耐心听我说并具体一点。我有一个在屏幕上“浮动”的对象(重力设置为 (0, -4))。所以它是一个“动态”物理体,并且它与所有其他物理体正确相互作用。碰撞监听器工作正常。但是,当对象(气球)的 Y 值达到 150 时,我希望该对象在 250 毫秒内过渡到屏幕上的较低位置。但是当我运行代码时,气球会转到屏幕上的随机点并且不一致。
local function move(event)
If (balloon.y <= 150) then
transition.to(balloon, {time = 250, x = balloon.x, y = 320);
end
end
Runtime:addEventListener("enterFrame", move);
我读到,由于 enterFrame
侦听器每 30-60 毫秒调用一次,因此需要更长的时间的转换基本上会重复调用该函数,永远不允许转换完成。如果这是问题所在,有更好的方法吗?
I am relatively new to Corona and am still unsure whether I understand transition.to
, so please bear with me and be specific. I have an object that is "floating" (gravity is set to (0, -4)) up on the screen. So it's a "dynamic" physics body, and it interacts properly with all other physics bodies. Collision listeners are working perfectly. However, when the object, a balloon, reaches a Y of 150, I want the object to transition to a lower location on the screen in 250ms. But when I run my code, the balloon goes to random points on the screen and is inconsistent.
local function move(event)
If (balloon.y <= 150) then
transition.to(balloon, {time = 250, x = balloon.x, y = 320);
end
end
Runtime:addEventListener("enterFrame", move);
I've read that since the enterFrame
listener is called every 30-60ms, transitions that take longer than that will basically call the function repeatedly, never allowing the transition to complete. If that is the problem,, is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想防止重复调用,请将标记
isInTransition
(这是任意的)放在balloon
上,并检查每个调用的状态。如果物理交互(例如碰撞)与
transition.to()
混合在一起,则物理不能很好地处理过渡。如果你想让气球移动到较低的位置而不发生碰撞,可以尝试
balloon.isSensor=true/false
。讨论此处< /a> 关于与您类似的案例。
If you wanted to prevent duplicate calls, put a flag
isInTransition
(this is arbitrary) onto theballoon
and check for its status for every call.Physics does not work well with transitions if there are physics interactions (e.g. collision) mixed with
transition.to()
.If you wanted the balloon to move to lower location without collisions, you can try
balloon.isSensor=true/false
.Discussion here about a case similar to yours.