having an issue where I can't stop the music from looping

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.
Post Reply
dagmar1177
Prole
Posts: 6
Joined: Fri May 11, 2012 2:35 am

having an issue where I can't stop the music from looping

Post by dagmar1177 »

ZombieWorld.love
Here's my most current version of the game
(115.57 KiB) Downloaded 65 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
User avatar
jradich
Party member
Posts: 100
Joined: Mon Dec 12, 2011 8:44 pm

Re: having an issue where I can't stop the music from loopin

Post by jradich »

You can put that snippet in the code tags, for easier viewing. And instead of

Code: Select all

setLooping
write

Code: Select all

isLooping
. Do this in the love.load().
Losing a friend's trust is the fastest way to lose a friend, forever. FOREVER!
dagmar1177
Prole
Posts: 6
Joined: Fri May 11, 2012 2:35 am

Re: having an issue where I can't stop the music from loopin

Post by dagmar1177 »

First thx for the tip for the forum. Second when I change the:

Code: Select all

setLooping
to

Code: Select all

isLooping
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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: having an issue where I can't stop the music from loopin

Post 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.
dagmar1177
Prole
Posts: 6
Joined: Fri May 11, 2012 2:35 am

Re: having an issue where I can't stop the music from loopin

Post by dagmar1177 »

Right so does that mean there's another callback function I need to put it in or is just love.load
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: having an issue where I can't stop the music from loopin

Post by Roland_Yonaba »

Just load your source, set the looping and start playing it inside love.load callback.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: having an issue where I can't stop the music from loopin

Post 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.
dagmar1177
Prole
Posts: 6
Joined: Fri May 11, 2012 2:35 am

Re: having an issue where I can't stop the music from loopin

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 56 guests