Today, I managed to fix an audio issue that I haven't been able to wrap my head around. Sorry – this sort of post doesn't really offer much eye candy for a devlog...
I wanted to trigger the dragon's wing sound just on certain frames. So, there's an audible gush of air when the wings “flap.” I was able to do this fine when the dragon's image_speed was 1. But in Game Maker, with room speeds of 60, that ends up being a crazy fast animation.
So, if I wanted to set the image_speed to 0.1, which visually looks appropriate at that room speed, it ends up creating odd decimal values throughout the image_index. So, triggering an animation at a precise subimage becomes mathematically complicated. If you're more savvy than I was, you might already know the solution. But it took me a while to arrive at it. At one point, I had the precise decimal image_index flying across the screen where the dragon used to be. I was thinking I needed to hit these exact values in the code, but it never worked - and it was the wrong solution.
In case someone else has this problem in the future and stumbles across this, here's what I was trying to do initially:
if (image_index) = 4
{
audio_play_sound(wing_sound,1,false);
}
That code works great with an image_speed or 1, but it's not reliable for any other value. The simple fix is to use Game Maker's floor or round functions to get rid of the decimal values introduced at other speeds. Here's the easy solution:
if floor(image_index) = 4
{
audio_play_sound(wing_sound,1,false);
}
You can't hear it in this screen (or my celebration when it finally worked) but it feels good to finally solve this pesky problem. For whatever reason, this issue was particularly hard for me to wrap my head around - probably because I couldn't visualize it. It feels good to finally put it to rest.