我无法让我的动画与过渡正常工作。

发布于 2024-12-29 17:46:07 字数 573 浏览 1 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻风 2025-01-05 17:46:07

如果您想防止重复调用,请将标记 isInTransition(这是任意的)放在 balloon 上,并检查每个调用的状态。

local function move(event)

    if not balloon.isInTransition then
        if (balloon.y <= 150) then
            transition.to(balloon, {time = 250, x = balloon.x, y = 320)
            balloon.isInTransition=true
        elseif balloon.y == 320 then
            balloon.isInTransition=nil
        end
    end
end

Runtime:addEventListener("enterFrame", move);

如果物理交互(例如碰撞)与 transition.to() 混合在一起,则物理不能很好地处理过渡。

如果你想让气球移动到较低的位置而不发生碰撞,可以尝试balloon.isSensor=true/false

讨论此处< /a> 关于与您类似的案例。

If you wanted to prevent duplicate calls, put a flag isInTransition (this is arbitrary) onto the balloon and check for its status for every call.

local function move(event)

    if not balloon.isInTransition then
        if (balloon.y <= 150) then
            transition.to(balloon, {time = 250, x = balloon.x, y = 320)
            balloon.isInTransition=true
        elseif balloon.y == 320 then
            balloon.isInTransition=nil
        end
    end
end

Runtime:addEventListener("enterFrame", move);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文