Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
L÷VE for Lua Game Programming

You're reading from   L÷VE for Lua Game Programming If you want to create 2D games for Windows, Linux, and OS X, this guide to the L?ñVE framework is a must. Written for hobbyists and professionals, it will help you leverage Lua for fast and easy game development.

Arrow left icon
Product type Paperback
Published in Sep 2013
Publisher Packt
ISBN-13 9781782161608
Length 106 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
AKINLAJA DAMILARE JOSHUA AKINLAJA DAMILARE JOSHUA
Author Profile Icon AKINLAJA DAMILARE JOSHUA
AKINLAJA DAMILARE JOSHUA
Arrow right icon
View More author details
Toc

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...

You have been reading a chapter from
L÷VE for Lua Game Programming
Published in: Sep 2013
Publisher: Packt
ISBN-13: 9781782161608
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime