Game Development Reference
In-Depth Information
return pixel;
}
]]
This also requires a slight change to the effect.func function:
function effect.func()
love.graphics.setPixelEffect(effect.effect)
love.graphics.draw(image)
end
What we have done is simply set the value of the pixel r , g , and b colors to be 1 minus the value,
which is similar to inverting the image's colors. For more effects, you can read up on GLSL at
http://www.opengl.org/documentation/glsl/ and also play around with the code. There are quite
a few samples on the forums that you can download and study. Apple has their own documentation
on GLSL at https://developer.apple.com/library/mac/#documentation/GraphicsImaging/
Conceptual/OpenGLShaderBuilderUserGuide/Introduction/Introduction.html which points to the
older version 1.20.8. This should be used instead of the newer versions as the version Apple has
information on is what is available on the iOS devices.
Making Sound
A game framework is incomplete if you cannot play sound. With LÖVE, first we need to load the
sound into memory and then play it as required.
popSound = love.audio.newSource("pop.ogg", "static")
static tells LÖVE that it needs to load and decode this sound entirely before it starts to play. This is
different from streaming, where the sound can be played in parts as it is streamed from disk.
To play the sound, we simply use
love.audio.play(popSound)
Let's create an example that makes a popping sound each time the window is clicked:
function love.load()
pop = love.audio.newSource("pop.ogg", "static")
end
function love.mousepressed(mx, my, mButton)
if mButton == "l" then
love.audio.play(popSound)
end
end
Apart from playing a sound, LÖVE also provides functions to increase and decrease the
volume. You can also change the pitch by simply using popSound:setPitch(value) , where
value has a range between 0 and 1. The same ranges apply for setVolume and can be set as
popSound:setVolume(value) .
 
Search WWH ::




Custom Search