SFX when walking - sync and regions

Started by rickious, Sat 27/12/2014 13:02:15

Previous topic - Next topic

rickious

I have a few different sfx for walking over different regions (floor types), ideally I wanted to sync these to the footsteps in the walk animation but i very much doubt this is possible especially when walking over different regions and switching sfx.

So.

Whats the best and neatest code to get sfx when walking, which seamlessly transitions to a different sfx when walking over different regions?  And also behaves when you have clicked 'use' 'look at' etc as well as 'walk to'.  Also would this be a global code as i only need 2-4 different walking sfx throughout the game.

Thank you in advance for any help.

EDIT
HAd a thought about a way to sync SFX even when changing walkable regions.  So, say a room has two different regions.  You play both synchronized SFX whenever the player walks, but depending on the region one is muted.  What do you think? do SFX play consistently at the same time as you start walking? Or is there sometimes a stall and the sfx playes late?
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

Gurok

Okay, I don't have a complete solution for you. I do it all manually. I use walkable area types, not regions. You could probably change this to use regions pretty easily. Here's the code I use to do footsteps:

Inside repeatedly_execute_always:
Code: ags

		target = character[index]; // This is inside a loop running through all characters in the game
		if(target.Moving && Character_Audio_LastFrame[index] != target.Frame && (target.Frame - 1) % 4 == 0)
		{ // Character_Audio_LastFrame is an array holding the last frame checked for each character
		// The above checks to make sure we're rendering a frame different from the last
		// Second part of the check makes sure it's one of the two contact frames. I have eight-frame walk cycles, so 1,2,3,*4*,5,6,7,*8* <-- Frames marked with *s are contact frames
			if(target.WithinViewport())
			{ // WithinViewport is an extender function I wrote to determine if a character intersects the current viewport
			// I only want to play a noise if they're on screen
				if(target == player)
				{ // If the current character is the player, we'll play foreground sounds
					if(GetWalkableAreaAt(target.x - GetViewportX(), target.y - GetViewportY()) == 2)
					{ // I use walkable areas of 2 to indicate grassy areas
						choice[0] = aFootstepGrassFG1;
						choice[1] = aFootstepGrassFG2;
						choice[2] = aFootstepGrassFG3;
						choice[3] = aFootstepGrassFG4;
					}
					else
					{ // Other areas are stone
					// The "choice" array is used to determine a random sound (below)
						choice[0] = aFootstepStoneFG1;
						choice[1] = aFootstepStoneFG2;
						choice[2] = aFootstepStoneFG3;
						choice[3] = aFootstepStoneFG4;
					}
				}
				else
				{
					if(GetWalkableAreaAt(target.x - GetViewportX(), target.y - GetViewportY()) == 2)
					{
						choice[0] = aFootstepGrassBG1; // Background sounds are -10.0db and low pass filtered
						choice[1] = aFootstepGrassBG2;
						choice[2] = aFootstepGrassBG3;
						choice[3] = aFootstepGrassBG4;
					}
					else
					{
						choice[0] = aFootstepStoneBG1;
						choice[1] = aFootstepStoneBG2;
						choice[2] = aFootstepStoneBG3;
						choice[3] = aFootstepStoneBG4;
					}
				}
				// Now we play a random sound from the array so that the walking doesn't sound monotonous
				// PlayAtCharacter is another extender function I wrote to automatically pan the sound appropriately
				// You could just use .Play() instead
				choice[Random(3)].PlayAtCharacter(target);
			}
			// Finally, we update the last considered frame for this character
			Character_Audio_LastFrame[index] = target.Frame;
		}
		else
			// Importantly, if the character has stopped moving, we set the last frame to an impossible value
			// That way, walking characters won't sometimes skip their first frame noise after they stop and start walking again
			if(!target.Moving && Character_Audio_LastFrame[index])
				Character_Audio_LastFrame[index] = 0;
	}
[img]http://7d4iqnx.gif;rWRLUuw.gi

rickious

Cheers dude.  And I can switch to walkable areas, suppose there is not much difference for this purpose? 

Ill read your code over and try and figure out whats what and give it a go.  The annotations are a great help.

thanks again.
--COMING SOON--
'Body Pharm' beta demo.

Body Pharm - coming soon!

SMF spam blocked by CleanTalk