A object with sound effect

Started by Olleh19, Tue 09/07/2019 12:22:23

Previous topic - Next topic

Olleh19

an object should sound when the player is near it, only. In otherwords a "passing by" sound. I'm thinking about doing the object as a "character" cause it should move as an animation aswell, and then when the player is near it. It should make a sound. Sorta like a passing motorbike or such.
Is it difficult to do? I was thinking about regions used that before, but that probably won't work. Since the player and the object should travel across the screen and they should met at random locations wherever on the screen.

Any help would be very much appreciated. Thanks

Khris

Try this:

Code: ags
// top of room script
AudioChannel* objectChannel;

  // in the room's load / after fadein function
  objectChannel = aSomeSound.Play();

  // in the room's repeatedly_execute function
  objectChannel.SetRoomLocation(oMachine.X, oMachine.Y);


Now you can simply call  .Move()  on the object.

If you want the object to be completely silent if the player isn't close, you might need additional logic.

Olleh19

Thanks Kris, i actually don't know much about the "soundsystem" as of yet. Just added sounds using the "asound.play();".
But i will give it a try!  :smiley:


Laura Hunt

Quote from: Olleh19 on Tue 09/07/2019 12:22:23I'm thinking about doing the object as a "character" cause it should move as an animation aswell

Just in case you're not aware, objects can be animated too. Just assign a view to it with Object.SetView and then use Object.Animate :)

Olleh19

Quote from: notarobotyet on Tue 09/07/2019 12:59:27
Quote from: Olleh19 on Tue 09/07/2019 12:22:23I'm thinking about doing the object as a "character" cause it should move as an animation aswell

Just in case you're not aware, objects can be animated too. Just assign a view to it with Object.SetView and then use Object.Animate :)

Thanks, Yes i know about that. I use objects all the time. Love animating it's so much fun  :grin


SMF spam blocked by CleanTalk