Loop sound while keydown

BlitzMax Forums/BlitzMax Beginners Area/Loop sound while keydown

Yahfree(Posted 2007) [#1]
I'm trying to play a burning sound while holding the acceleration key button...

I'v tried loading a sound into loop mode, then trying to play the sound while the key is pressed, then not when its not held down.. but failed so far..

Any ideas?


Jesse(Posted 2007) [#2]
if keydown(?) 
 if not channelplaying(?) then playsound(?,?)
else
 if channelPlaying(?)then stopchannel(?)
endif



Yahfree(Posted 2007) [#3]
woops, no wonder i'm not getting a responce.... thought i already replyed

I tried this before, and it didnt work, i get the error: Unable to convert something.audio.TSound to TChannel

heres my code at the moment:
		If KeyDown(KEY_UP)
		
			'Afterburner effect
			Local par1:TPartical = New TPartical
				par1.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par2:TPartical = New TPartical
				par2.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par3:TPartical = New TPartical
				par3.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par4:TPartical = New TPartical
				par4.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par5:TPartical = New TPartical
				par5.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
				
			vx:+Cos(angle)*accel
			vy:+Sin(angle)*accel
 
 			If Not ChannelPlaying(afterburn) PlaySound(afterburn)

		Else
			If ChannelPlaying(afterburn) StopChannel(afterburn)
		EndIf


and i'm loading it like this:
Global afterburn:TSound = LoadSound("Media\afterburn.wav",SOUND_LOOP)


thanks for the help :)


tonyg(Posted 2007) [#4]
You seem to be checking whether a channel is playing but using a TSound to check it.
e.g. afterburn is a TSound and not a TChannel.


Yahfree(Posted 2007) [#5]
how do i make it a channel? i tried changing:

Global afterburn:TSound = LoadSound("Media\afterburn.wav",SOUND_LOOP)

to

Global afterburn:TChannel = LoadSound("Media\afterburn.wav",SOUND_LOOP)


still, an error.. I'm stumped..


tonyg(Posted 2007) [#6]
Slightly edited from the doc...
' channelplaying.bmx

sound:tsound = LoadSound ("shoot.wav")

Input "Hit return to begin channelplaying test, use ctrl-C to exit"

channel:tchannel=playsound (sound)
while true
	print "ChannelPlaying(channel)="+ChannelPlaying(channel)
wend

you can also use the allocchannel cmd


Jesse(Posted 2007) [#7]
it should be something like this:
		Global aftchannel:TChannel = AllocChannel()

and this:
		.
		.
		.
		.
		If KeyDown(KEY_UP)
		
			'Afterburner effect
			Local par1:TPartical = New TPartical
				par1.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par2:TPartical = New TPartical
				par2.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par3:TPartical = New TPartical
				par3.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par4:TPartical = New TPartical
				par4.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
			Local par5:TPartical = New TPartical
				par5.Create(x-(Cos(angle))*10,y-Rand(-2,8)-(Sin(angle))*10,20)
				
			vx:+Cos(angle)*accel
			vy:+Sin(angle)*accel
 
 			If Not ChannelPlaying(aftchannel) PlaySound(afterburn,aftchannel)

		Else
			If ChannelPlaying(aftchannel) StopChannel(aftchannel)
		EndIf



Yahfree(Posted 2007) [#8]
seems to work, thanks