4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
9.32k stars 795 forks source link

Music/Sound Offset Conditions do not work with "Equals" operator #1886

Open Silver-Streak opened 4 years ago

Silver-Streak commented 4 years ago

Describe the bug

While trying to create a workaround for the general bug/issue with delay on playing sounds/music, I attempted to find an alternative for better looping music that have an "Intro" piece. What I've discovered is that the "The playing offset of the music/sound on channel" condition does not work properly if you use the = operator. It does work with other operators.

For more detail: Many games have a short, unique, "intro" portion of background music. It then has a longer piece that loops endlessly and has a seamless loop transition.

To Reproduce

Steps to reproduce the behavior:

  1. Add an event with the Play the sound "filenamehere" on channel 1, vol: 100, loop: on action. Loop can be on or off, and this can be sound or music, there is no difference.
  2. Add another event with the condition The playing offset of the sound on channel 1 = 1.000 (once it reaches an offset of 1 second/1000 milliseconds). If using the music action in step 1 above, use the music action here.
  3. Add some actions to this second event, even something like Stop sound on channel 1
  4. Run Preview. Even after 1 second, the music keeps playing.
  5. Change the condition from the = (equal) operator to >= (greather than or equal).
  6. Run preview. After 1 second, the actions will happen.

Attached is an example project. Currently set up to use the = operator, which never triggers, change it to >= for it to work. OffsetBug.zip

(License Attribution: music is from YouFulca/Wingless Seraph)

Other details

OS: Win10 Pro GD Version: 5.0.0-beta97 (Long term I'd like to submit a bug or feature request to enhance sound/music playing in general, but I need to spend time thinking through/researching a good alternative solution)

4ian commented 4 years ago

The issue is that the "=" is technically working as expected, but because times in games is "discrete", you never reach exactly 1.000000 second (you're for example at 0.9998 second, then at the next frame it's now something like 1.012).

The good way of doing a test like you want to do would be to check if the playing offset is >1 and was the frame before <1 - something that is a bit more complex that a simple "=". I think this would need to be a separate condition, and we should probably warn against using = in such conditions (though it can be useful if you want to test you're at 0.0 - but any other value is not possible).

Silver-Streak commented 4 years ago

@4ian Yep, I eventually worked around this by using ">=" and my offset instead of = .

Honestly, since this is very specific to audio offsets, and I'd bet 99% of the time this would be used for proper looping: This may be better solved by updating the sound/music events to allow you to input a "Loop at" attribute that you input the offset you want it to occur at, and then a "loop to" attribute to determine where it loops to? Maybe?

Silver-Streak commented 1 year ago

@4ian This still exists as an issue in 5.1.157. Should the = operator be removed from the conditions, or that loop action be added?