A question about music

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Party member
Posts: 137
Joined: Mon Jul 07, 2014 11:04 am

Re: A question about music

Post by sphyrth » Thu Jun 20, 2019 1:01 pm

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:
Yes.png (14.15 KiB) Viewed 3611 times
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.

User avatar
Posts: 44
Joined: Thu Apr 04, 2019 3:32 pm

Re: A question about music

Post by CrimsonGuy » Thu Jun 20, 2019 7:08 pm

^In general loading any type of resource (music or images) on every tick of the update will lead to a big performance hit.

User avatar
Party member
Posts: 2126
Joined: Sun Oct 18, 2015 2:58 pm

Re: A question about music

Post by pgimeno » Fri Jun 21, 2019 10:05 am

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.

User avatar
Party member
Posts: 2862
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary

Re: A question about music

Post by zorg » Fri Jun 21, 2019 3:46 pm

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" )



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
Me and my stuff :3True 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests