Sound Issue, possibly bug possibly scope :/
Monkey Forums/Monkey Programming/Sound Issue, possibly bug possibly scope :/
| ||
Hay all. OK. so my project is using Diddy, and I have about 7 or 8 source files, all being imported, basically each source fil holds a class and all its nic nac's/ So I have been trying to use Diddy's sound to play a bullet effect when I shoot, but its been failing badly with random errors, and no sound. SO.. I went to my first file, my build file, and created a global called BulletSound:Sound, then when I create an instance of Game, I am loading the sound BulletSound = LoadSound("sound/shot1.ogg") . OK here is where things get a bit weird, my first screen (again diddy) is my title screen, now if I use the following in my titlescr source , If KeyHit(KEY_H) then PlaySound (BulletSound,0,0) the sound will play. IF. I move that line of code from titlesrc.monkey into my playsrc.monkey and have it try and play when the player hits Z to fire, A) the sound does not play, and b) on some targets it just crashes. I have no clue why a global variable would not work in one source , but does in another, its got me baffled there is no variable conflicts BulletSound is only ever used the one time for this stupid sound test so its not clashing with anything else. I would post source but as I said the project is getting kinda large. any help with this would be amazing, cos its really got me scratching my head. |
| ||
Seems like when I switch screens on diddy, the sound stops working. is switching screens freeing up all media even those stored in global variables? |
| ||
Without seeing your source and/or file structure it's really hard for me to give suggestions. :/ |
| ||
Looks like there are multiple soundbanks. One automatically by Diddy in DiddyApp and another by you in your Screen. Had that once with images. Just a guess. |
| ||
ok.. mainfile '****************************************************** 'Modules '****************************************************** Import diddy '****************************************************** 'Additional Code. '****************************************************** Import titlescr Import helpscr Import scorescr Import gamescr Import alien Import anglefont.angelfont Import anglefont.simpleinput Import anglefont.simpletextbox Import clevel Import cplayer Import cplayerbullet Import cpath Import cparticle '****************************************************** ' Globals. '****************************************************** Global SilverFont:AngelFont Global RedFont:AngelFont Global YellowFont:AngelFont Global BlueFont:AngelFont '****************************************************** 'Launch Point '****************************************************** Function Main:Int() game = New MyGame() game.debugKeyOn = True game.drawFPSOn = True Return 1 End '****************************************************** ' Game Screen Setup. '****************************************************** Global ScoreScr :Screen = New ScoreScreen() 'high score table. Global PlayScr :Screen = New GameScreen() 'Game Play. Global HelpScr :Screen = New HelpScreen() 'display game help. Global TitleScr :Screen = New TitleScreen() 'Title / Menu screen. 'Global speed:Int =1 Global ImageSpriteSheet:Image Global BulletSound:Sound Global FxChannel:Int '****************************************************** ' Launch Game '****************************************************** ' The Game Class MyGame Extends DiddyApp Method OnCreate:Int() Seed = RealMillisecs() Super.OnCreate() SetGraphics(480, 800) SetScreenSize(480,800, True) SetUpdateRate 60 LoadImages() LoadSounds() LoadFonts() CreatePaths() TitleScr.PreStart() FxChannel = 0 Return 0 End Method '*********************** '* Load Images '*********************** Method LoadImages:Void() ImageSpriteSheet = LoadImage("graphics/sprites.png") images.Load("backgrounds/title_bg.png", "", False) images.Load("backgrounds/help_01.png","",False) 'grab a few images into a global handle for easy access later. AlienBulletImage[0] = ImageSpriteSheet.GrabImage(432,108,54,54,1,Image.MidHandle) AlienBulletImage[1] = ImageSpriteSheet.GrabImage(536,108,54,54,1,Image.MidHandle) RedBulletImage = ImageSpriteSheet.GrabImage(378,0,54,54,1,Image.MidHandle) GreenBulletImage = ImageSpriteSheet.GrabImage(378,54,54,54,1,Image.MidHandle) BlueBulletImage = ImageSpriteSheet.GrabImage(378,109,54,54,1,Image.MidHandle) ParticleImage[0] = ImageSpriteSheet.GrabImage(594,108,54,54,1,Image.MidHandle) ParticleImage[1] = ImageSpriteSheet.GrabImage(648,108,54,54,1,Image.MidHandle) ParticleImage[2] = ImageSpriteSheet.GrabImage(702,108,54,54,1,Image.MidHandle) ParticleImage[3] = ImageSpriteSheet.GrabImage(486,162,54,54,1,Image.MidHandle) PathNodeImage = ImageSpriteSheet.GrabImage(540,162,54,54,1,Image.MidHandle) End Method Method LoadFonts:Void() SilverFont = New AngelFont() SilverFont.italicSkew = 0.15 SilverFont.LoadFont("graphics/font/main") YellowFont = New AngelFont() YellowFont.italicSkew = 0.15 YellowFont.LoadFont("graphics/font/main_yellow") RedFont = New AngelFont() RedFont.italicSkew = 0.15 RedFont.LoadFont("graphics/font/main_red") BlueFont = New AngelFont() BlueFont.italicSkew = 0.15 BlueFont.LoadFont("graphics/font/main_blue") End Method '*********************** '* Load Sounds '*********************** Method LoadSounds:Void() BulletSound = LoadSound("sound/shot1.ogg") End Method End and this is the titlescreen where I play the sound first. Import iTerm Class TitleScreen Extends Screen Field background:GameImage Field ts:Sound Method New() name = "Title" End Method Start:Void() background = game.images.Find("title_bg") game.screenFade.Start(50, False) ts = BulletSound End Method Render:Void() DrawImage background.image, 0, 0 'Scale 2, 2 'DrawText "Title Screen", SCREEN_WIDTH2 / 2, (SCREEN_HEIGHT2-30) / 2, 0.5, 0.5 SilverFont.DrawText("Title Screen", SCREEN_WIDTH / 2,SCREEN_HEIGHT / 2,AngelFont.ALIGN_CENTER) YellowFont.DrawText("Hit G for game play", SCREEN_WIDTH / 2,(SCREEN_HEIGHT / 2)+20,AngelFont.ALIGN_CENTER) RedFont.DrawText("Hit H for Help", SCREEN_WIDTH / 2,(SCREEN_HEIGHT / 2)+40,AngelFont.ALIGN_CENTER) BlueFont.DrawText("Thanks. :)", SCREEN_WIDTH / 2,(SCREEN_HEIGHT / 2)+60,AngelFont.ALIGN_CENTER) End Method Update:Void() If KeyHit(KEY_G) game.screenFade.Start(50, True, True, True) game.nextScreen = PlayScr End If KeyHit(KEY_Z) AssertNotNull(Self.ts, "Couldn't load the sound!") PlaySound (Self.ts,FxChannel,0) FxChannel=FxChannel+1 If FxChannel>=5 Then FxChannel=1 End If If KeyHit(KEY_H) game.screenFade.Start(50,True,True,True) game.nextScreen = HelpScr End If If KeyHit(KEY_S) game.screenFade.Start(50,True,True,True) game.nextScreen = ScoreScr End If End End NOW.. there are other screens .. ok so if I run this, I can play the sound by hitting the Z key on the main menu, once I press H or G and goto a new screen, when I come back to the title screen Z no longer makes the sound play. and if I try and play the sound in any other screen other than title it fails to play at all, it will only play the first screen I load. |
| ||
for further head scratching... I took out all the normal sound code and went back to diddies system.. I used the boom3.mp3 from the diddy sound example to make sure the file was fine. and flash gave me this error. Error loading sound sounds/boom3.mp3 Monkey runtime error: Error loading sound sounds/boom3.mp3 E:/Code/MonkeyPro/modules/diddy/assert.monkey<106> E:/Code/MonkeyPro/modules/diddy/assert.monkey<20> E:/Code/MonkeyPro/modules/diddy/functions.monkey<180> E:/Code/MonkeyPro/modules/diddy/framework.monkey<912> E:/Code/MonkeyPro/modules/diddy/framework.monkey<876> E:/Source/Monkey/Invaders/iTerm.monkey<163> E:/Source/Monkey/Invaders/iTerm.monkey<103> E:/Code/MonkeyPro/modules/mojo/app.monkey<53> what the hell am I doing wrong or is this indeed a scope bug when dealing with multiple source files. |
| ||
Where is your sound file? Diddy looks in "sounds" for GameSound, but your code above when using Sound is this: BulletSound = LoadSound("sound/shot1.ogg") sound != sounds And for Diddy you dont need to supply the folder. sounds.Load("shot1.ogg") ;) Also you dont need to set the seed or the updaterate when using diddy... it does this for you. |
| ||
I fixed it. Had to delete all monkey installations. download the new version, and start from scratch, code now compiles and runs. something left over or not written correctly from the new version I guess must have corrupted something. |
| ||
You do know that when you move between Monkey versions that you need to delete your project's build folder, dont ya? |
| ||
Yeah I had done that when I got the update. Don't know what the issue was but it's fixed now. And I made a new sound folder to use with the play sound and load sound functions . As for set update rate it's in there cOs I keep testing at diff frame rates. |
| ||
Delete not Important. |
| ||
As for set update rate it's in there cOs I keep testing at diff frame rates. Then set the game.FPS in the Main function: Function Main:Int() game = New MyGame() game.debugKeyOn = True game.drawFPSOn = True game.FPS = 60 Return 1 End Also can you please edit your posts instead of all the double posts - it wouldnt be too bad, but your banner is huge! Least its working now... |
| ||
My banner is a standard forum size, but if you think it's a little to large I will shrink it down some more. I have added that game.FPS code, thanks for the tip, I can tell there is still a lot about that framework that I need to discover :) enjoying it so far. |