-- Rascalls Game Source Code - Main.lua --
function love.draw()
Title()
MenuItems()
end
function love.update()
love.graphics.setBackgroundColor(math.random(255),math.random(255),200)
end
function Title()
TitleFont = love.graphics.newFont("WTD.ttf", 64)
love.graphics.setFont(TitleFont)
TitleText = love.graphics.print("Rascalls Game", love.graphics.getWidth() / 2 - 205, 80)
end
function MenuItems()
MenuFont = love.graphics.newFont("WTD.ttf", 32)
love.graphics.setFont(MenuFont)
love.graphics.print("Single Player", love.graphics.getWidth() / 2 - 205, 120)
end
I want to make a floating menu so the text will move as if its floating on the canvas, Can any body lend a hand and teach me how I would go about this with LUA.
-- Rascalls Game Source Code - Main.lua --
function love.draw()
Title()
MenuItems()
end
function love.update()
love.graphics.setBackgroundColor(math.random(255),math.random(255),200)
end
function Title()
TitleFont = love.graphics.newFont("WTD.ttf", 64)
love.graphics.setFont(TitleFont)
TitleText = love.graphics.print("Rascalls Game", love.graphics.getWidth() / 2 - 205, 80)
end
function MenuItems()
MenuFont = love.graphics.newFont("WTD.ttf", 32)
love.graphics.setFont(MenuFont)
love.graphics.print("Single Player", love.graphics.getWidth() / 2 - 205, 120)
end
I want to make a floating menu so the text will move as if its floating on the canvas, Can any body lend a hand and teach me how I would go about this with LUA.
Basically you are saying you have windows, with text, like a title, that you want to move with the windows? If thats the case then just set your "Menu Items/ Menu Text" x/y variables to be whatever your window x/y variables are. Then just add or subtract what's needed to get the text in the right place.
function love.update() -- this function can take an argument (dt), which you might find useful
love.graphics.setBackgroundColor(math.random(255),math.random(255),200) -- this could be a problem for epileptic users
end
function Title()
TitleFont = love.graphics.newFont("WTD.ttf", 64) -- creating a font every frame is extremely bad -- as if firefox would need to download the web page you're looking 60 times a second
love.graphics.setFont(TitleFont)
TitleText = love.graphics.print("Rascalls Game", love.graphics.getWidth() / 2 - 205, 80) -- love.graphics.print doesn't actually return anything, there's no need to do TitleText = nil.
end
function MenuItems()
MenuFont = love.graphics.newFont("WTD.ttf", 32) -- same as above
love.graphics.setFont(MenuFont)
love.graphics.print("Single Player", love.graphics.getWidth() / 2 - 205, 120) -- strangely, you do it right this time
end
I only made a variable for TextTitle because I tried to use it like a instance.. and the random colours is for me because Its only a example..
also " TitleFont = love.graphics.newFont("WTD.ttf", 64) -- creating a font every frame is extremely bad -- as if firefox would need to download the web page you're looking 60 times a second" Its in the draw function? I never knew the draw function drew every second I only thought update function works like that.
JRascall wrote:I never knew the draw function drew every second I only thought update function works like that.
Nope. If it drew once, it would be more of a picture than a game, wouldn't it?
See http://love2d.org/wiki/love.run for the default game loop. (Yes, you can change it, but you'll rarely ever have to do that, unless your name is Jasoco.)
Sorry, but am coming from a (limited) C# and XNA background and never used a draw function.
Ok well Ill work on it follow some tutorials or somin thing, any way thanks.
JRascall wrote:Sorry, but am coming from a (limited) C# and XNA background and never used a draw function.
Ok well Ill work on it follow some tutorials or somin thing, any way thanks.
It's really quite basic. Bascially, any LOVE game will include love.load, love.update, and load.draw. All of which are pretty self explanatory.
Load is for anything you want loaded on startup, like images and sounds. Though images or any graphics related things arent actually drawn until you add them to love.draw. So a basic way to load an image and display it is this.
function love.load()
image = love.graphics.newImage("imagelocation")
end
function love.update(dt)
end
function love.draw()
love.graphics.draw(image, 100, 100)
end
So in the end, if you want something to appear on screen, you will have to use draw.
function love.load()
text = {} -- here we create a table called "text"
text.words = "hello world!" -- here we add a string entry to that table, with the string "hello World"
text.x = 100 -- an x variable for text
text.y = 100 -- a y variable for text
end
function love.update(dt)
if love.keyboard.isDown("p") then -- this will take text.x and add "1" to it if the "p" button is pressed
text.x = text.x + 1 * dt
end
end
function love.draw()
love.graphics.print(text.words, text.x, text.y) -- this prints the text at "text.x" and "text.y"
end
Thats basic code that will take the current "X" variable and add 1 to it. Since the text is being drawn at "text.x" and "text.y" the text will move whenever you change those variables. Hope this helps.
Sorry the code is sloppy, I wrote it in the browser so I had no access to "tab". Thus it was difficult to indent.