admin管理员组

文章数量:1400533

I am trying to implement a screen transition effect in Crank Storyboard using Lua. The goal is to play an animation first and then switch to the target screen. However, when I run my script, the animation does not play—it directly switches to the next screen.

Here's the code I am using:

Copy
Edit
function hide_info_layer(screen)
    if screen then
        gre.set_layer_attrs_global(screen, { hidden = 1 })
    else
        print("Error: screen is nil in hide_info_layer")
    end
end

function screen_transition(target_screen)
    if target_screen then
        print("Transitioning to:", target_screen)
        gre.set_value("target_sc", target_screen)
        gre.send_event("gre.load_screen", target_screen) -- Directly load the screen
    else
        print("Error: target_screen is nil in screen_transition")
    end
end

function cb_presstart_button(mapargs)
    local current_screen = mapargs.context_screen
    local control = mapargs.context_control

    -- Fetch correct screen name
    local target_screen = gre.get_value(string.format("%s.screen_name1", control))

    print("Current Screen:", current_screen)
    print("Target Screen:", target_screen)

    if current_screen == target_screen then
        print("Already on target screen, no transition needed")
        return
    end

    hide_info_layer(current_screen)

    if current_screen == "start" then
        gre.set_value("target_sc", target_screen)
        print("Triggering animation: punch_NewAnimation")
        gre.animation_trigger("punch_NewAnimation")
    else
        print("Calling screen_transition")
        screen_transition(target_screen)
    end
end

Observed Behavior: The animation punch_NewAnimation does not play when transitioning between screens.

The screen changes immediately after calling gre.animation_trigger(), skipping the animation effect.

The console prints the expected logs but does not execute the animation before the screen transition.

Attempts to Resolve:

  1. Delaying Screen Change Until Animation Ends

  2. I tried adding a delay after triggering the animation but didn't find a direct way to ensure the transition happens only after the animation completes.

  3. Using Animation Callbacks

  4. I attempted to listen for an animation event before triggering the screen change but couldn't find a working solution.

Expected Behavior: The animation (punch_NewAnimation) should play completely.

After the animation finishes, the screen should transition to target_screen.

Question: How can I ensure that the animation plays fully before transitioning to the next screen? Is there a way to use animation callbacks or events to handle this properly in Crank Storyboard?

本文标签: