Jump to content


Photo

Sound playback speed.


  • Please log in to reply
5 replies to this topic

#1 thisiswaysilly

thisiswaysilly

    GMC Member

  • GMC Member
  • 3 posts
  • Version:Unknown

Posted 24 April 2012 - 08:38 PM

Hello GameMaker community, I'm having an interesting problem. I've used GameMaker on and off for years, and recently(last year or so) I've been learning GML. So anyway here is the problem. I'm using this code to increase my character's image_speed as she accelerates
if keyboard_check(left) or keyboard_check(right) && !place_free(x,y+1){
    image_speed=hspeed/20;}
and her running sprite is just her alternating her feet using two images. I have a small step sound and what I'd like to do is have the sound play whenever her image_index chages.
please help.
  • 0

#2 stainedofmind

stainedofmind

    GMC Member

  • GMC Member
  • 368 posts
  • Version:GM8

Posted 24 April 2012 - 10:12 PM

Try this:

if (image_index = floor(image_index))
{
      sound_play(sndFootStep);
}

  • 0

#3 thisiswaysilly

thisiswaysilly

    GMC Member

  • GMC Member
  • 3 posts
  • Version:Unknown

Posted 25 April 2012 - 01:49 AM

Try this:

if (image_index = floor(image_index))
{
      sound_play(sndFootStep);
}

thanks, but it didn't quite work. it would rapidly play my sound when i was standing. so i added the variable "run" to detect whether or not she was running but it caused the sound to no longer play at all.
  • 0

#4 stainedofmind

stainedofmind

    GMC Member

  • GMC Member
  • 368 posts
  • Version:GM8

Posted 26 April 2012 - 01:49 AM

Ah yes. I hadn't taken into consideration that it would continuously play while standing still. It should have worked when you implemented the "run" check, however. Can you post your new code so I can have a look at it?
  • 0

#5 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9314 posts
  • Version:Unknown

Posted 26 April 2012 - 02:24 AM

You need to check for when the image_index changes, which means you need to keep track of its previous value. Try this:

/* CREATE */
lastIndex = floor(image_index);

/* STEP */
if (floor(image_index) != lastIndex) {
  sound_play(footstep_snd);
  lastIndex = floor(image_index);
}

-IMP
  • 0

#6 thisiswaysilly

thisiswaysilly

    GMC Member

  • GMC Member
  • 3 posts
  • Version:Unknown

Posted 26 April 2012 - 03:53 AM

You need to check for when the image_index changes, which means you need to keep track of its previous value. Try this:

/* CREATE */
lastIndex = floor(image_index);

/* STEP */
if (floor(image_index) != lastIndex) {
  sound_play(footstep_snd);
  lastIndex = floor(image_index);
}

-IMP

Thank you so much! I knew I needed to keep track of the previous value, but I wasn't sure how to approach the problem. This is a wonderful solution. Many thanks to both of you.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users