Polygon Help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
DeadInternal
Prole
Posts: 9
Joined: Fri May 25, 2012 1:53 am

Polygon Help

Post by DeadInternal »

I'm relatively new to Love2D and I've been messing around with some random functions lately. I came across the love.graphics.polygon() function and for whatever reason it doesn't seem to work. Here's the code I have as of now.

The polygon function is inside the love.load function. The polygon doesn't show up at all.

Code: Select all

local text = "The key you pressed is : "

function createtext(txt, x, y)
function love.draw()
love.graphics.printf(txt, x, y, 500, "left")
end
end 

function love.load()
love.graphics.setBackgroundColor(200,200,200)
love.graphics.setCaption("ohai")
love.graphics.setColor(0, 100, 0)
love.graphics.polygon("line", 10, 400, 200, 50, 300, 20, 500, 500)
createtext("Please press a key", 400, 400)
end 

function love.keypressed(key)
text = text..""..key
createtext(text, 0, 400)
end
The polygon code is inside the love.load() function.


Also, I would like help with another thing. I'm currently on a Mac. Is there a way for me to make a .exe file from a .love file on a Mac? I already know how to make a .app file.

Any help is appreciate. Thanks!
Attachments
Love2DTest.love
My testing file.
(779 Bytes) Downloaded 140 times
- Active guitarist
- Active programmer
User avatar
AaronWizard
Citizen
Posts: 68
Joined: Sun Nov 06, 2011 2:45 pm
Location: Canada

Re: Polygon Help

Post by AaronWizard »

All the love.graphics functions for drawing stuff are meant to be called in the love.draw callback. love.load is meant for, well, loading things like images and sounds as well as setting variables.

https://love2d.org/wiki/love
https://love2d.org/wiki/love.draw
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Polygon Help

Post by Nixola »

You can create an exe on every system, check out Game Distribution. Download the zipped LOVE from the homepage and use that
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
DeadInternal
Prole
Posts: 9
Joined: Fri May 25, 2012 1:53 am

Re: Polygon Help

Post by DeadInternal »

AaronWizard wrote:All the love.graphics functions for drawing stuff are meant to be called in the love.draw callback. love.load is meant for, well, loading things like images and sounds as well as setting variables.

https://love2d.org/wiki/love
https://love2d.org/wiki/love.draw
Thanks! I didn't know that all drawing functions required love.draw. That's useful knowledge to remember.
Nixola wrote:You can create an exe on every system, check out Game Distribution. Download the zipped LOVE from the homepage and use that
The steps there are for different operating systems to make the executable file for the operating system that you made the .love file out of. The instructions don't tell how to make a .exe on a Mac, or how to make a .app on a Windows.
- Active guitarist
- Active programmer
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Polygon Help

Post by bartbes »

Well, that's easy:

Code: Select all

cat love.exe game.love > game.exe
I could've sworn that was on there too, though.
User avatar
DeadInternal
Prole
Posts: 9
Joined: Fri May 25, 2012 1:53 am

Re: Polygon Help

Post by DeadInternal »

bartbes wrote:Well, that's easy:

Code: Select all

cat love.exe game.love > game.exe
I could've sworn that was on there too, though.
Thanks!

Also, I've been having issues with the love.draw() function. I guess I'm not doing it correct or something.

Code: Select all

local text = "The key you pressed is : "

function createtext(txt, x, y)
function love.draw()
love.graphics.printf(txt, x, y, 500, "left")
end
end 

function love.load()
love.graphics.setBackgroundColor(200,200,200)
love.graphics.setCaption("ohai")
love.graphics.setColor(0, 100, 0)
shape = love.graphics.polygon("fill", 10, 100, 10, 50, 50, 100, 50, 50)
createtext("Please press a key", 400, 400)
end 
function love.draw()
love.graphics.draw(shape)
end

function love.keypressed(key)
text = text..""..key
createtext(text, 0, 400)
end
I based it off the hamster ball code. I also changed the points making it a rectangular/square type shape. It still doesn't appear.
Attachments
LoveTest1.love
My testing file
(794 Bytes) Downloaded 127 times
- Active guitarist
- Active programmer
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Polygon Help

Post by bartbes »

You define love.draw twice, and you can't. It's just an ordinary function, and the last write overwrites any previous ones.

Code: Select all

function createtext(txt, x, y)
function love.draw()
love.graphics.printf(txt, x, y, 500, "left")
end
end 
That, specifically, is the offending code., you'll probably want something along these lines:

Code: Select all

function love.draw()
    --love.graphics.draw(shape) --> note: this doesn't work, love.graphics.polygon draws a polygon, instead of creating a "polygon object"
    love.graphics.polygon("fill", 10, 100, 10, 50, 50, 100, 50, 50)
    love.graphics.print(text, 400, 400) -- where 'text' is a variable containing the current message you want drawn on the screen
end
Dynamically adding (and/or removing) stuff from being drawn is a bit harder, and would require you (as in, the programmer) to write the necessary infrastructure.
User avatar
DeadInternal
Prole
Posts: 9
Joined: Fri May 25, 2012 1:53 am

Re: Polygon Help

Post by DeadInternal »

Ah, okay. So basically my issue was that I had the love.draw function twice. Thanks for all your help.
- Active guitarist
- Active programmer
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests