Game Development Reference
In-Depth Information
function love.draw()
lg.drawq(sheet, frames[curr], (_W-(tileWd*scale))/2, (_H-(tileHt*scale))/2, 0, scale, scale)
end
function love.update(dt)
delay = delay + 1
if delay > frameSpeed then
delay = 0
curr = curr + 1
if curr > frameCount then curr = 1 end
end
end
In our love.load function, we create and store the quads, representing each frame. This helps in
achieving speed and efficiency. We can simply draw any frame in the sequence after that by simply
referencing the quad as stored in the table. To get the fourth frame, we simply reference the fourth
quad (i.e., frames[4] ). In our drawq function, we are multiplying tileWd and tileHt by the scale value
and also passing the scale as a parameter. This helps to create the animation at the specified scale,
which is double in our case (i.e., 2).
To make the animation visible, we slow it down by using a loop in the love.update function, where
we increment a frame every 5 updates. This is just for illustration purposes; if this animation were
critical, then you would have to rely on the dt (time elapsed) instead of 5 updates to achieve the
same frame rate on all platforms. This could mean some skipped frames if the system you are
running it on is slow.
We can see our stickman hobble, as shown in Figure 11-9 .
Figure 11-9. Our stickman animation
Search WWH ::




Custom Search