Translations of this page:

How do I implement surface-dependent footstep sounds?

Implementing footstep sounds is easy, you just add a sound to certain frames of the walking animations. But sometimes you may need to change the footstep sounds depending on the surface the character is walking on.

First, we need to define scene areas for different surfaces (sand, metal, grass…). In WME, you can add custom properties to any game object, including the scene regions. Let's say we have a grassy field in our scene. Create a scene region covering the entire grass area. In the region properties in Scene Edit?, click the “Custom…” button. Add a new property, and fill in
Name: xSurface
Value: grass.
Now the character will know he/she is walking on grass.

WME allows you to trigger script events from within the animations. We well use this to call a piece of script whenever character's feet hit the ground. Open your walking animations in Sprite Edit?, and edit each frame where the foot is on ground (there should be two such frames in each walking animation, one for each foot). In the frame properties, there is an “Event” field. Fill in “footstep” in those hit-the-ground frames.
Now the animation will trigger a “footstep” event everytime the character should play a sound.

Last thing we need to do is to handle the event in a script. Open a script attached to your actor in a text editor and type in a code similar to this:

on "footstep" 
{ 
 // get a region the actor is standing in 
 var Reg = Scene.GetRegionAt(this.X, this.Y); 
 if (Reg!=null) 
 { 
   // play a sound depenging on a surface 
   // "xSurface" is a custom property we defined in SceneEdit 
   switch(Reg.xSurface) 
   { 
     case "grass": 
       this.PlaySound("footsteps\grass.ogg"); 
     break; 
 
     case "wood": 
       this.PlaySound("footsteps\wood.ogg"); 
     break; 
 
     // add more sounds here... 
   } 
 } 
}


 
kbase/how_do_i_implement_surface-dependent_footstep_sounds.txt · Last modified: 2009/02/25 18:31 by Mnemonic
Recent changes RSS feed Creative Commons License Driven by DokuWiki