Example

MUSIC example

2

was8bit 2022-06-08 11:37 (Edited)

Demonstrates how to implement more than one background melody, that constantly plays, along with game sounds playing... as well as how to stop the background melody

TAP screen to toggle thru melody0, melody2 and no background melody...

(Note, the # indicates the Pattern# a melody starts on... the ARROW settings in the upper right corner help control the melody looping)


was8bit 2022-06-08 11:43 (Edited)

If you have different melodies which start at differing positions, it would be best to use an array to store the starting points of each one...

Example:
DIM MELODYNUM(6)
FOR I=1 TO 6
READ MELODYNUM(I)
NEXT I
DATA 0,3,7,9,10,15

Then to play, use MUSIC MELODYNUM(3)


was8bit 2022-06-08 11:49

Remember, Any game works best with a main game loop with one WAIT VBL

DO
... game code...

WAIT VBL
LOOP

this sets up your code to execute at a rate or 1/60 a second, or 60 times a second.... it not only allows MUSIC to function, but allows all things including animations to be consistent...

Also, NX functions at a 1/60 rate, so it will give your game its best performance :)


Log in to reply.