I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: Hop on November 16, 2015, 11:18:16 AM

Title: Objects pulsing/animating to music?
Post by: Hop on November 16, 2015, 11:18:16 AM
Not sure if this is something that is possible, but I was thinking it would be cool to have spikes or something similar pulse along with the beat of a song. Is this doable? I've only been playing with Game Maker for a few weeks so I do not know much about it.  Thanks!
Title: Re: Objects pulsing/animating to music?
Post by: TheGamerGuy500 on November 16, 2015, 03:55:11 PM
You'd have to know the exact timings of the music for it to work.
You could...
Split the music file into a set of files that just contain the beats at the start of each file...
Set a timeline and have it pulsate with specific intervals, but on laggier computers, it would quickly desync. You'd have to make it so the music goes at a speed relative to the game's actual speed and current FPS for that case.
Get an extension that can somehow do that.

I'm sure there's a foolproof method out there somewhere
Title: Re: Objects pulsing/animating to music?
Post by: lawatson on November 16, 2015, 05:00:38 PM
Try getting the BPM of the song/sound, multiplying that by 5/6, and then making a value increase by that much until it gets over an amount of beats and then setting it back to 0 and doing the action. It's been done a lot with avoidances in timelines and stuff.
Title: Re: Objects pulsing/animating to music?
Post by: Stepcore on November 17, 2015, 08:07:36 AM
Sure it is, Fun Jumps 2 does it.
You need an object that counts up by 1 for every beat so you need to find the bpm and then find the amount of frames per beat as lawatson said. Of course, this object should be persistent.
Code: [Select]
framesPerBeat = (framerate*60)/(BPM)or
Code: [Select]
framesPerBeat = framerate/(/BPM/60)I think.

I would recommend instead of setting it back to 0, just having it count up and use MOD to find the beat to move on. Then you can find any specific beat in the song and do stuff there. You should probably reset it to 0 when the song loops though.
With this method if you need every beat just MOD 1, every other beat MOD 2 and so on, like this:

Code: [Select]
if (beat mod 2 == 0) pulse=true;Of course only check this once per beat, not once per frame.
Code: [Select]
if (beat!=previousbeat && beat mod 2 == 0){
pulse=true;
previousbeat=beat;
}

This will desync if you use show_message or in any way pause the game, change the music etc without regard for the beat timer. So remember to keep track of this.

There is probably a better way but I think this is more or less how I did it.
Title: Re: Objects pulsing/animating to music?
Post by: Hop on November 17, 2015, 04:58:42 PM
Thanks for the suggestions! I'll have to try that out.