I think I was able to reproduce the error. You put the important section of code into love.load() instead of love.update().
This is the barebones of what the guys are trying to explain:
As a programming preference, I don't like getting a "newSource" everytime the music stops. I'd rather have all the music stored in an array instead.
A question about music
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- CrimsonGuy
- Prole
- Posts: 48
- Joined: Thu Apr 04, 2019 3:32 pm
Re: A question about music
^In general loading any type of resource (music or images) on every tick of the update will lead to a big performance hit.
Re: A question about music
Well, music is not stopped at every tick, so it should not do that. But loading the next song on the fly could lead to pauses in the middle of the game, which is a good point by sphyrth.
- zorg
- Party member
- Posts: 3444
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: A question about music
So in the end, a baseline could be something like this:
Code: Select all
local music = {}
local music_volume = 0.5
local current_music = 0
local count_music = 11
function love.load()
for i=0,count_music-1 do
music[i] = love.audio.newSource("music/mus_".. i ..".mp3", "stream" )
music[i]:setVolume(music_volume)
end
music[0]:play()
end
function love.update(dt)
if not music[current_music]:isPlaying() then
current_music = (current_music + 1) % count_music -- from 0 to 10
-- current_music = love.math.random(0,count_music-1) -- if you want to shuffle
music[current_music]:play()
end
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Google [Bot] and 220 guests