Page 1 of 1
having an issue where I can't stop the music from looping
Posted: Fri May 11, 2012 2:54 am
by dagmar1177
- ZombieWorld.love
- Here's my most current version of the game
- (115.57 KiB) Downloaded 74 times
I'm trying to learn as I go as I'm kinda as new as it gets when it comes to programing but I got some basics down and was trying experiment with making a start up theme that would play ONCE when the game would start now when I wrote the program it was initially like this
function love.load()
opening = love.audio.newSource("horror017.mp3" ,"static")
reddeath = love.graphics.newImage("RedMoon.jpg")
X = 0
y = 0
end
function love.draw()
love.graphics.draw(reddeath, x,y)
love.graphics.print("Loading Death", 700,580)
opening:setPitch(0.7)
opening:setLooping(false)
love.audio.play(opening)
end
however do to the nature of the .draw information it would contently repeat after it finished playing the sound clip i found that if i reworte the program as such:
function love.load()
opening = love.audio.newSource("horror017.mp3" ,"static")
reddeath = love.graphics.newImage("RedMoon.jpg")
X = 0
y = 0
opening:setPitch(0.7)
opening:setLooping(false)
love.audio.play(opening)
end
function love.draw()
love.graphics.draw(reddeath, x,y)
love.graphics.print("Loading Death", 700,580)
end
it would work however telling it that looping was false was now pointless considering that .load only runs once anyways Im wondering if im useing the wrong function type or that i did something else wrong with the setLooping(false) information please let me know if this is the only way of doing it or if im doing something else wrong I would love to know so I can learn from it
Re: having an issue where I can't stop the music from loopin
Posted: Fri May 11, 2012 3:04 am
by jradich
You can put that snippet in the code tags, for easier viewing. And instead of
write
. Do this in the love.load().
Re: having an issue where I can't stop the music from loopin
Posted: Fri May 11, 2012 4:02 am
by dagmar1177
First thx for the tip for the forum. Second when I change the:
to
I still had the same problem where I had to put the audio.play in the love.load to prevent the sound clip from looping. I feel there should be another way to do this, but if there's not thx again for trying to help a newbie like me
Re: having an issue where I can't stop the music from loopin
Posted: Fri May 11, 2012 6:50 am
by bartbes
You do need setLooping, instead of isLooping, contrary to what jradich told you.
However, you call love.audio.play every single frame, hence it will always restart.
Re: having an issue where I can't stop the music from loopin
Posted: Fri May 11, 2012 11:45 am
by dagmar1177
Right so does that mean there's another callback function I need to put it in or is just love.load
Re: having an issue where I can't stop the music from loopin
Posted: Fri May 11, 2012 12:07 pm
by Roland_Yonaba
Just load your source, set the looping and start playing it inside love.load callback.
Re: having an issue where I can't stop the music from loopin
Posted: Fri May 11, 2012 12:41 pm
by bartbes
Or, find an event, or filter one, that doesn't get called as often. Maybe only start music once they click 'Start game' in the menu, or something like that.
Re: having an issue where I can't stop the music from loopin
Posted: Fri May 11, 2012 8:19 pm
by dagmar1177
Well thx for the info i just wanted to know if there was another way in case i needed to do something like this later but for the current situation i think putting in the .load will be the easiest thing thx for all the help and advice though