Drawing 2D objects
LÖve's love.graphics
module already has in-built functions for drawing specific shapes such as a circle, arc, and rectangle. So let's draw all these shapes in a single game. Create a new game folder, rename it as shapes
, open a new main.lua
file in this directory, and edit it by adding the following code:
function love.load() –--loads all we need in game --- set color for our shapes RGB love.graphics.setColor(0, 0, 0, 225) --- set the background color RGB love.graphics.setBackgroundColor(225, 153, 0) end function love.draw() –--function to display/draw content to screen ---draw circle with parameters(mode, x-pos, y-pos, radius, segments) love.graphics.circle("fill", 200, 300, 50, 50) ---draw rectangle with parameters(mode, x-pos, y-pos, width, height) love.graphics.rectangle("fill", 300, 300, 100, 100) ---draw an arc with parameters(mode,x-pos,y-pos,radius,angle1,angle2) love.graphics.arc("fill", 450, 300, 100, math.pi/5, math.pi/2) end
By following...