Programming looping audio clips in a Hotspot

Started by Pinosas, Mon 25/05/2020 14:36:02

Previous topic - Next topic

Pinosas

Hi there !

I'm a fresh beginner at AGS and i don't know how to translate my idea into the scripting.

What i want is to play an audio clip in a loop whenever my character is inside a Hotspot, even if the character is walking around. I've found out that the "Stand on Hotspot" event should occur repeatedly while the player character is standing on the hotspot, so I used it and wrote the audio script I read in the tutorial:

function hHotspot1_WalkOn()
{audio1.Play();}


However, when i run the game the audio only pops out when the character leaves the Hotspot, and not while it's inside. Besides that problem, I guess i should write another script to make the audio go in a loop (?)

I have searched in the forum and tutorial for hours and couldn't find anything on the subject so any kind of help would be very much appreciated !!

Matti

Quote from: Pinosas on Mon 25/05/2020 14:36:02
However, when i run the game the audio only pops out when the character leaves the Hotspot, and not while it's inside.

That sounds weird, but I've never used the "Stand on Hotspot" event and would need to test it myself. You could try using a region instead of a hotspot though.

Quote
Besides that problem, I guess i should write another script to make the audio go in a loop (?)

audio.play has a RepeatStyle-parameter:

AudioClip.Play(optional AudioPriority, optional RepeatStyle)

kaizen101

Code: ags


function hclownG_WalkOn()
{

  if (Hotspot.GetAtRoomXY(cPlayer.x, cPlayer.y) == hclownG) 
  {
    soundX.Play(eAudioPriorityHigh, eRepeat);
  }
  else
  {
    soundX.Stop();
  }
}



Hi I test your code and it works fine, it plays when I'm on a hotspot, I also test stopping it when I'm not on the hotspot

Laura Hunt

I think the issue is that when you use "stand on hotspot", your code gets executed constantly while the character is standing on the hotspot. Thus, your audio clip gets triggered over and over and over again which is why you don't hear it.

In your case I would switch to using regions instead of hotspots, since regions have "Walk on region" and "Walk off region" events. You would trigger your audio when the character walks onto the region, and stop it when they walk off.


Pinosas

Thank you guys so much !

Reading your replies I tried using Regions, the events  "Walk on region" and "Walk off region" suited my necessities:


function region1_WalksOnto()
{soundX.Play();}

function region1_WalksOff()
{soundX.Stop();}


Also the audio clip loops automatically !




SMF spam blocked by CleanTalk