Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / NOOB Qestion regarding audio.

Author
Message
DazzyF
11
Years of Service
User Offline
Joined: 13th May 2012
Location:
Posted: 11th Nov 2012 19:22
Hi guys, I wondered if you could help, I am trying to work out how I can play one sound at a time, but I am rather puzzled on how I can do it.
I want the accellerometer to play one sound in say the X axis and a different sound in the Y axis.
However I am just getting loads of sounds playing all at once.
Here is the code I have used, but get an error with the "getsoundsplaying" command.
I wondered if anyone could please give me any tips on how I can accomplish this?

Thanks in advance.

Here's the "basic" code I am using at the moment:-

// Check Accelerometer Movement and play sound.

x# = GetDirectionX ( )
y# = GetDirectionY ( )
if x#=>1 then Playsound ( 1 )
if y#=>1 then Playsound ( 2 )
getsoundsplaying ( 1 ) then stopsound (2)
getsoundsplaying ( 2 ) then stopsound (1)

www.dazzyscds.co.uk
DazzyF
11
Years of Service
User Offline
Joined: 13th May 2012
Location:
Posted: 11th Nov 2012 19:29
I have tried this comment aswell, but then I don't get a sound:

x# = GetDirectionX ( )
y# = GetDirectionY ( )
if x#=>1 then Playsound ( 1 )
if y#=>1 then Playsound ( 2 )
if getsoundexists ( 1 ) then stopsound (2)
if getsoundexists ( 2 ) then stopsound (1)

www.dazzyscds.co.uk
DazzyF
11
Years of Service
User Offline
Joined: 13th May 2012
Location:
Posted: 11th Nov 2012 19:36
I have played a bit more and come up with this:
// Check Accelerometer Movement and play sound.
x# = GetDirectionX ( )
y# = GetDirectionY ( )
if x#=>1 then Playsound ( 2 )
if y#=>1 then Playsound ( 1 )
if x#=0 then stopsound ( 2 )
if y#=0 then stopsound ( 1 )

BUT, it still plays more than one instance of the sounds, does anyone have any ideas so it only plays One instance of each sound?

Thanks.

www.dazzyscds.co.uk
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 11th Nov 2012 19:53
I think you need to save current values. Many sounds can play at once. The slightest jitter on X or Y axes here will trigger another sound.

If you want to play only one sound you should stop the currently playing sound before launching the new one! But do you really want to play a new sound on every movement??? I don't think so!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Nov 2012 20:03
The reason your getsoundsplaying lines were returning errors is because there is no 'if ' to start the line.

The GetDirectX/Y commands return values between -0.9999 and +0.9999. So your first two if statements, comparing the direction values, will never return true. And, you should be compare to floating point numbers, not integer values.

It is very hard to get only the X or Y direction changing by itself. When a player tilts the device, you are likely to see values in both cases.

You should probably try something like this:


Using getsoundexists the way you do in your second post guarantees that the sounds will always stop playing because the sounds always exist (once you've loaded them).

Cheers,
Ancient Lady
AGK Community Tester
DazzyF
11
Years of Service
User Offline
Joined: 13th May 2012
Location:
Posted: 11th Nov 2012 21:35
Thank you so much for your advice, Ancient Lady, your code snippet helped alot, I did have to tweak a couple of things (the 0.25 in the x & y if statements), but it has made it lots better, still will be experimenting.
I just really want to learn this so much.

Thank you again.

Daz.

www.dazzyscds.co.uk

Login to post a reply

Server time is: 2024-05-07 05:52:10
Your offset time is: 2024-05-07 05:52:10