What does the offset mean in gui.play_flipbook() play properties? (SOLVED)

gui.play_flipbook(node,animation,[complete_function],[play_properties])

offset: number The normalized initial value of the animation cursor when the animation starts playing.

Could I get an example of how this is used? I don’t understand based on the wording of the documentation. Does “animation cursor” mean the animation frame?

gui.play_flipbook(gui.get_node("box"), hash("anim"), nil, {offset = 0.5})

The animation cursor is a number that reflects how far into the animation you are. Normalized in this context means that the value you set is between 0-1 (so a percentage, rather than 1-[total_num_frames]).

gui.play_flipbook(gui.get_node("box"), hash("anim"), nil, {offset = 4/7})

Note that the default value of the animation cursor is 0. So, if in the example above you have 7 frames, setting the value at 4/7 will actually start you at frame 3. I assume it just starts at the closest frame to the value you have input.

3 Likes

Okay, that’s what I suspected. Never seen the term “cursor” before though, so I was a little hesitant.

Unfortunately, I’m not sure if your example is correct, even though it looks good. Here’s what I have:

Capture
2

The offset I pass in changes based on the menu item selected. It can be 0, 0.33, 0.66, and 0.99. Regardless, the gui node displays only the first animation frame (sound_box_0). Not sure what’s going on here. I replaced the second offset variable in { offset = offset } to a each of the above literals just in case, but no success.

Does it work if you set the animation playback to something besides None in the atlas?

2 Likes

Yes it does, actually. Thanks for the suggestion. I usually keep 0 FPS animations set to none, but not this time I suppose.

It would be nice to know exactly how the normalization works, though. Setting offset to 1.0 or 0.0 shows the same final animation frame, instead of 0.0 showing the first frame.

Edit: I just did some quick testing, and found that offset indeed interprets values <= 0 as the last animation frame. The first frame starts at 0 + ϵ and the last frame once again appears at >= 1.0.

1 Like