Adam's Lair Forum

game development and casual madness
It is currently 2019/09/17, 15:15

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Sound
PostPosted: 2014/01/30, 07:48 
Junior Member
Junior Member
User avatar

Joined: 2014/01/20, 04:07
Posts: 26
Role: Hobbyist
My specific problem is (hopefully) simple, but I can't figure out what to try next. I have no "sound effects" in the game. Just some scenes which have "music" over them. Sometimes this music should loop, other times just play once.

Well, I cannot get the music to not loop. I can clear the queue once I leave scene, but until then it will loop.

Here is my only music code in the OnInit function:

Code:
SoundBudgetPad bgMusic = DualityApp.Sound.Music.Push(GameRes.Data.breakaway_theme_Sound, SoundBudgetPriority.Background, 0f);
            bgMusic.Instance.Looped = false;




Thoughts?

Thanks so much.


PS: Are there any resources relating to Duality/Dualitor and sound? You have some code in the Asteroids and Tetris examples, of course. And in the wiki-tutorials you mention attaching a SoundEmitter, but don't go into any further detail (iirc). But that's about all I could find. If not, this may be something worth making? Just a thought :)


Top
 Profile  
 
 Post subject: Re: Sound
PostPosted: 2014/01/30, 11:24 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
By default, music and ambient sound you push to the queue aren't looped, so the source code you posted should work. I suspect that you might be pushing the same music onto the stack multiple times, which would result in replaying it again and again - because lower stack elements will pause when not getting any weight and replay, once the topmost stack element has finished playing.

Are you checking the InitContext in OnInit? Because, OnInit will be called multiple times with different contexts, but you usually just want to react on InitContext.Activate.

In my own game project, I just do the following:

Code:
// Play music when necessary
if (!DualityApp.Sound.Music.IsAnyScheduled)
{
   DualityApp.Sound.Music.Push(
      MathF.Rnd.OneOf(musicList),
      SoundBudgetPriority.Background,
      0.0f);
}


Using this code within an Update method results in a random track being played until it is finished, and then scheduling another random track, etc.

Right now, there are no tutorial resources available on the topic of sound, music and ambient. I agree that someone should probably write some. Didn't get around to it yet, so.. I guess it's either either "later" or "someone else" :D

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Sound
PostPosted: 2014/01/30, 16:35 
Junior Member
Junior Member
User avatar

Joined: 2014/01/20, 04:07
Posts: 26
Role: Hobbyist
Quote:
Are you checking the InitContext in OnInit? Because, OnInit will be called multiple times with different contexts, but you usually just want to react on InitContext.Activate.


I'm pretty sure this is the cause of the problem. I'll have to wait until tonight before I can test, but I am definitely NOT checking context. I will be sure to do that from now on, since in most cases that is all I want from OnInit.

So much to learn!


Also, I totally understand that you're busy. I definitely want to write tutorials and documentation, but I really need to play with everything more before I would feel comfortable. But all of my games (for a while at least) will be open source, editor included, so maybe people can learn a little from my example.


Edit: Oh also I hope that my barrage of questions on this message board will over-time help to form some documentation. I know I am always ready to dive into message boards when looking for answers.


Top
 Profile  
 
 Post subject: Re: Sound
PostPosted: 2014/01/30, 17:15 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2073
Location: Germany
Role: Professional
charles wrote:
Edit: Oh also I hope that my barrage of questions on this message board will over-time help to form some documentation.


Don't worry, I'm pretty sure they will. It's kind of the original reason why I've set up this forum anyway. Before that, a lot of questions where arriving directly via E-Mail, so I often had to answer the same things twice, because all the answers were private.

Also, I'm kind of hoping we'll have some other Duality experts here sooner or later, who will be able write tutorials and answer questions as well.

By the way, you are not the only one falling into that OnInit trap. I've actually set up a new issue on GitHub to deal with this in the long run.

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
 Post subject: Re: Sound
PostPosted: 2014/02/01, 23:20 
Junior Member
Junior Member
User avatar

Joined: 2014/01/20, 04:07
Posts: 26
Role: Hobbyist
The OnInit context check worked perfectly, by the way. Got everything to work as desired. Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group