Restarting Channels?

Blitz3D Forums/Blitz3D Programming/Restarting Channels?

Cubed Inc.(Posted 2014) [#1]
Is there any way to restart a channel in Blitz3d? My game's music is stored in channels, so I'd like to know if it is possible. The reason? Well, look at it like this: let's say in the first level of the game, there's a certain track that plays. In the second level of the game, a different track is played while the other track is paused. In the third level, the same track from the first level is resumed, but it resumes from a certain place in its duration as opposed to just starting over. This is for obvious reasons, since I'm simply pausing the track rather than stopping it, but I feel that it would be better if the track would restart if it plays again in a different level.
Whoo - I'm a real long-winded sonuvab*tch, ain't I? Anyway, does anyone had the same problem as me before, and perhaps even a solution? Any help if greatly appreciated.


Stevie G(Posted 2014) [#2]
Yes. Use PauseChannel and ResumeChannel.


Cubed Inc.(Posted 2014) [#3]
Using the pause channel will only temporarily stop the track in its place until it is resumed; it does not 'restart' the track all together. I'm looking for a way to make the track (channel) restart from the beginning of whatever music is loaded.


Stevie G(Posted 2014) [#4]
Sorry misunderstood the question. Your games music is not stored in channels, it it is stored in sounds and played through channels. Just use stopchannel and playsound.

Assuming you have 2 looped songs loaded as ...

Song1 = Loadsound( "Song1.wav" )
Song2 = loadsound( "Song2.wav" )
Loopsound Song1
Loopsound Song2

[Play Song1]
MyMusicChannel = playsound( Song1 )
[Stop song1]
StopChannel MyMusicChannel

[Play Song2]
MyMusicChannel = playsound( Song2 )
[Stop song2]
StopChannel MyMusicChannel

[Play Song1 again]
MyMusicChannel = playsound( Song1 )

Each time you call playsound the next available channel is assigned. You don't need separate channels for each song unless you want to cross fade between the two. You will likely want to fade the sound out using channelvolume and when this is low enough use stopchannel.


Cubed Inc.(Posted 2014) [#5]
Worked like a charm. Thanks!