Log In  

Hello there,

I am playing the music from a function called intro.
This function is run in the update loop.
When the game state is intro then intro is showed and this is the moment I'd like to hear some music.

Problem is that the intro function is called every time the update loop restarts and therefore the music restarts everytime producing a choppy noise.

How can I solve this issue?

My code is available here:
https://github.com/ltpitt/pico-8-pong/blob/master/pico-8-pong.p8

Thanks for your time and help :)

P#38875 2017-03-30 07:38 ( Edited 2017-03-31 12:04)

something like that?

function togglemusic(n)
if (music_playing) then
music(-1) music_playing=false
else
music(n) music_playing=true
end
end

also I think there are peeks and pokes for the music whereabouts but I never looked into that.

edit: oups, sorry, not what you asked for.
this should do:

function startmusic(n)
if (not music_playing) then
music(n) music_playing=true
end
end

function stopmusic()
music(-1) music_playing=false
end

call startmusic() in intro()

P#38878 2017-03-30 09:58 ( Edited 2017-03-30 14:05)
:: ltpitt

Sadly it is not working :(

If I use the 2nd function you pasted and then I call startmuc in intro the game starts playing even if I'm still in intro (and I get no music).

P#38908 2017-03-31 05:13 ( Edited 2017-03-31 09:13)

there must be something else going on, these function shouldn't interfere with your game logic at all.

P#38912 2017-03-31 07:32 ( Edited 2017-03-31 11:32)
:: ltpitt

You're 100% right, I was using the wrong music code and it started playing - rightfully - my game's sfx :)

Really thanks :)

P#38915 2017-03-31 08:04 ( Edited 2017-03-31 12:04)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-05-31 08:13 | 0.011s | 4194k | Q:20