|
Post by Marble (LS5) on Jul 13, 2012 19:19:46 GMT -5
In most games, there are tracks that have an intro, and at a certain point, begins the first part of a looped track. From there, the intro portion no longer plays for the rest of the session. This is a simple code I put together in 5 minutes.
Game.bb
Add this to tGame_StageProperties
Field StartMusic And this under tGame
Field MusicChn
Stage.bb
Put this in the music loading part of Game_Stage_Start() - replace the original music loading
Case "startmusic" Game\Stage\Properties\StartMusic = LoadSound("Music/"+xmlNodeDataGet(InformationChildNode)) Case "music" Game\Stage\Properties\Music = LoadSound("Music/"+xmlNodeDataGet(InformationChildNode)) LoopSound(Game\Stage\Properties\Music)
At the end of this function, there is a code that begins the music, replace that with this
Game\MusicChn = PlaySound(Game\Stage\Properties\StartMusic)
Put this anywhere in Stage_Step() but not within an If - EndIf loop For example, I put it under Objects_Update(Game\DeltaTime)
; Loop Transition If ChannelPlaying(Game\MusicChn)=False Then StopChannel(Game\MusicChn) Game\MusicChn = PlaySound(Game\Stage\Properties\Music) EndIf ;------------------
Now, if you wanted to play an intro as well as a loop track, you can add this to a Stage.xml document
<startmusic>gfact1-p1.wav</startmusic> <music>gfact1-p2.wav</music>
just replace these music names with yours
The Outcome:
|
|
|
Post by 06hypersonic60 on Jul 14, 2012 4:26:02 GMT -5
good. And that's exactly the code I'm using to. And for that you should have a perfect looping sound
|
|
|
Post by Redler Red7 on Jul 14, 2012 5:08:39 GMT -5
the only problem now is finding where it loops (shouldn't be too much of a problem though)
|
|
|
Post by Marble (LS5) on Jul 14, 2012 6:17:57 GMT -5
Yeahh... Just find the loop point in 1 track and remove everything past it to make the intro track. Remove everything before it to make the loop.
|
|