I have a question about music
BlitzPlus Forums/BlitzPlus Beginners Area/I have a question about music| 
 | ||
| I'm trying to find out what do I add to my game program below if I want to change the music each time my character collides with a door? Details about what I'm trying to do is below inside some brackets (so that my problem could be easier to find): 
Graphics 1640, 1000 
HENRY = LoadAnimImage ("HenryMoveAroundIII.PNG",400,370,0,14)
BACKGROUND = LoadImage ("DockII.jpg")
BACKGROUND2= LoadImage ("My Backyard2.png")
DOOR = LoadImage ("Door.png")
DOOR2 = LoadImage ("Door3.png")
;----------------------------------------------------------------------------------------------------------------------------
		             ;MUSIC
		             ;------
	;Below is the music that I want to have played 
									
						
MUSIC = PlayMusic ("EarthToneNewFire.wav") ;This music starts from the very beginning when my charcter HENRY
hasn't collided with a door.
MUSIC2 = LoadSound ("04 Gianni Schicchi- O mio babbino caro.wav") ;This music starts when my charcter 
HAS collided with the FIRST door and hence, it turns off the beginning music.	
MUSIC3 = LoadSound ("Way back.wav"); This music starts when my character has collided with the SECOND door and hence, turns off
; the music from when my character collided with the first door.
;---------------------------------------------------------------------------------------------------------------------------
Type HENRY
	Field x,y
	Field frame
End Type
Type DOOR
	Field x,y
End Type 
Type DOOR2
	Field x,y
End Type 
Type BACKGROUND
	Field x,y
	Field image
End Type 
h.HENRY = New HENRY
h\x = 500
h\y = 250
h\frame = 0
door1st.DOOR = New DOOR
door1st\x = 500
door1st\y = 25
door2nd.DOOR2 = New DOOR2
door2nd\x = 700
door2nd\y = 110
b.BACKGROUND = New BACKGROUND
b\x = 100
b\y = 0
b\image = BACKGROUND
While Not KeyDown(1)
   Cls 
				
TileImage (b\image,b\x,b\y)
   If KeyHit(25)	
      h\frame = h\frame + 1
      If  h\frame > 7
         h\frame = 6	
      EndIf
      ;
      If h\frame < 6
         h\frame = 6
      EndIf					
   EndIf					
				
  
   If KeyHit(24)	
      h\frame = h\frame + 1
      If  h\frame > 9
         h\frame = 8	
      EndIf
      
         h\frame = 8
      EndIf					
   	
   If KeyDown(205)
      h\x = h\x + 3
      h\frame = h\frame + 1
      If h\frame > 2 Then 
         h\frame = 1
      EndIf
 
      If h\frame < 0
         h\frame = 0
      EndIf
   EndIf
   If KeyDown(203)
      h\x = h\x - 3
      h\frame = h\frame + 1
      If h\frame > 5 Then 
         h\frame = 4
      EndIf
    
      If h\frame < 4
         h\frame = 4
      EndIf
   EndIf
;-------------------------------------------------------
;Inside these brackets is the part I need help with 
;-------------------------------------------------------	   
If ImagesCollide (HENRY, h\x, h\y,0,DOOR, door1st\x, door1st\y,0) Then 
      
      door1st\x = 300000        ;When HENRY collides with this 
                                 ;door1st\x, it stops the beginning music 
                                 ;and changes to a new song
		
				
						
	door2nd\x = 100
	door2nd\y = 250
	b\image = BACKGROUND2
  EndIf 
If ImagesCollide (HENRY, h\x, h\y,0,DOOR2, door2nd\x, door2nd\y,0) Then 
      
              door2nd\x = 700000	 ;When HENRY collides with 
                                               ;door2nd\x, it stops the music from the   
                                               ;FIRST door and changes to a new song   
                                               ;again.
							
						
				
		
             b\image = BACKGROUND2
						
						
						
 EndIf 
;--------------------------------------------------------------------
;Thanks, from here that would be all the help I need for now.
;I'll come back if I have anymore questions.
;--------------------------------------------------------------------
DrawImage (DOOR, door1st\x,door1st\y)
DrawImage (DOOR2, door2nd\x,door2nd\y)
DrawImage (HENRY,h\x,h\y,h\frame)
	
   Flip
Wend 
Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 | 
| 
 | ||
| The code below is just a direct port of your psuedo code. But the best solution I can think of is to have all you music loaded, looped and paused (loadsound(filename.wav, 3)) in an array. Then use a global variable to track the current song and a simple state machine to update the music.... global current_song = 0 music1 = loadsound("filename.wav") music2 = loadsound("filename.wav") music3 = loadsound("filename.wav") dim songs(2) songs(0) = Playsound(music1,3) songs(1) = Playsound(music2,3) songs(2) = Playsound(music3,3) while true ; handel input ; handel events If (character collides with a door) then change_music(door_number) EndIf ; render graphic Wend End Function change_music(index) StopChannel(songs(current_channel)) ResumeChannel(songs(index)) current_channel = index End Function | 
| 
 | ||
| Thanks Moore, it worked! |