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.
-
GloriousDerp
- Prole
- Posts: 6
- Joined: Tue Feb 25, 2014 10:52 pm
Post
by GloriousDerp »
I need help trying to play a sound when objects hit something.
Code: Select all
if objects.box == objects.box2 then
love.audio.play(sound)
end
objects.box = {}
objects.box.body = love.physics.newBody(world, 160, 300, "dynamic")
objects.box.shape = love.physics.newRectangleShape(50, 100)
objects.box.fixture = love.physics.newFixture(objects.box.body, objects.box.shape)
objects.box.fixture:setRestitution(1)
objects.box.body:setFixedRotation(true)
objects.box2 = {}
objects.box2.body = love.physics.newBody(world, 880, 300, "dynamic")
objects.box2.shape = love.physics.newRectangleShape(50, 100)
objects.box2.fixture = love.physics.newFixture(objects.box2.body, objects.box2.shape)
objects.box2.fixture:setRestitution(1)
objects.box2.body:setFixedRotation(true)
-
Autophoenix
- Prole
- Posts: 40
- Joined: Thu Mar 06, 2014 4:18 pm
- Location: Rio de Janeiro, Brazil
Post
by Autophoenix »
Create a variable in love.load(). Call it 'playsound', for example.
Code: Select all
function love.load()
playsound = false
end
And then, in update, remove love.audio.play(sound). Replace it with this:
Code: Select all
if objects.box == objects.box2 then
playsound = true
end
To play the sound:
Code: Select all
function love.draw()
if playsound == true then
love.audio.play(sound)
playsound = false
end
end
a² = b² + c²
-
LuaWeaver
- Party member
- Posts: 183
- Joined: Wed Mar 02, 2011 11:15 pm
- Location: Ohio, USA
Post
by LuaWeaver »
There's an edit button for a reason.

"your actions cause me to infer your ego is the size of three houses" -finley
Users browsing this forum: Bing [Bot] and 32 guests