Game Development Reference
In-Depth Information
Polygons
Polygons are drawn using the function
love.graphics.polygon
, which has the following syntax:
love.graphics.polygon(mode, vertices)
The vertices make up a table with the points to draw the shape. The following example draws a
triangle pointing downward:
love.graphics.polygon ("fill", 100,100,200,100,150,200)
Note
If you are using
fill
mode, the polygons must be convex and simple; otherwise, they can
produce rendering artifacts.
love.graphics.quad
We can create a quad using the
newQuad
function and then draw it on the screen using the
drawq
function. This can be very useful for creating animation sheets.
Figure 11-8.
Sprite sheet to be used for animating the stick figure (courtesy of Bonzo Industries;
http://bonzo_industries.
lg = love.graphics
sheet = lg.newImage("stick.png")
wd, ht = sheet:getWidth(), sheet:getHeight()
frameCount = 11
frameSpeed = 5
tileWd, tileHt = 39, 62
delay = 0
curr = 1
scale = 2
frames = {}
function love.load()
for i=1, frameCount do
frames[i] = lg.newQuad((i-1)*tileWd, 0, tileWd, tileHt)
end
end