Page 1 of 1
Polygon Help
Posted: Fri May 25, 2012 2:03 am
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!
Re: Polygon Help
Posted: Fri May 25, 2012 4:49 am
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
Re: Polygon Help
Posted: Fri May 25, 2012 9:10 am
by Nixola
You can create an exe on every system, check out
Game Distribution. Download the zipped LOVE from the homepage and use that
Re: Polygon Help
Posted: Fri May 25, 2012 10:04 pm
by DeadInternal
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.
Re: Polygon Help
Posted: Fri May 25, 2012 10:25 pm
by bartbes
Well, that's easy:
I could've sworn that was on there too, though.
Re: Polygon Help
Posted: Fri May 25, 2012 10:31 pm
by DeadInternal
bartbes wrote:Well, that's easy:
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.
Re: Polygon Help
Posted: Fri May 25, 2012 10:53 pm
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.
Re: Polygon Help
Posted: Fri May 25, 2012 11:18 pm
by DeadInternal
Ah, okay. So basically my issue was that I had the love.draw function twice. Thanks for all your help.