Hey guys,
So I've made a simple menu, just with a logo and background music, along with a nice 'debug' part in the top left telling me the FPS, dt and which keys/mousebuttons are being pressed.
1.So my first question, i'm using " fps = love.timer.getFPS( )" to get the fps, then printing it in the " love.graphics.print(fps .." FPS", 0, 30, 0)" way.
But... it says 0 all the time. Can somebody just explain why? Is it because i'm on the menu which is static (nothings moving).
2. Can I have someone post a reply that's a simple "How to make buttons" please? As in explain every part of it, i've seen another forum post about simple buttons, and I do understand, but i'd rather learn in terms similar to the wiki if possible Not "Download this and copy it in" or "just do this".
3. When the user clicks 'New Game' is there some way for it to move from main.lua to... game.lua or something? So that I can have the main.lua as the menu and for global variables, and then the main game will be in another .lua file?
Thanks in advance
-NT
[SOLVED]main menu questions (buttons, loading other)...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED]main menu questions (buttons, loading other)...
Last edited by ntpspe on Mon Aug 08, 2011 2:00 pm, edited 1 time in total.
Re: main menu questions (buttons, loading other .lua files e
PS: I think someone should do a button tutorial in the wiki
Re: main menu questions (buttons, loading other .lua files e
First, don't double post.
To do buttons without any third-party libraries, you'd have to manually check mouse positions and see if they are within a certain area of the screen, and then draw a corresponding image.
Sounds like you're setting the fps variable in love.load() or in the global scope. Try putting that bit of code in love.update().ntpspe wrote: 1.So my first question, i'm using " fps = love.timer.getFPS( )" to get the fps, then printing it in the " love.graphics.print(fps .." FPS", 0, 30, 0)" way.
But... it says 0 all the time. Can somebody just explain why? Is it because i'm on the menu which is static (nothings moving).
It isn't as easy as "just do this" unless you want to download something and use in your project.2. Can I have someone post a reply that's a simple "How to make buttons" please? As in explain every part of it, i've seen another forum post about simple buttons, and I do understand, but i'd rather learn in terms similar to the wiki if possible Not "Download this and copy it in" or "just do this".
To do buttons without any third-party libraries, you'd have to manually check mouse positions and see if they are within a certain area of the screen, and then draw a corresponding image.
Make your love.update and love.draw callbacks do different stuff depending on what "state" the game is in. Something like this:3. When the user clicks 'New Game' is there some way for it to move from main.lua to... game.lua or something? So that I can have the main.lua as the menu and for global variables, and then the main game will be in another .lua file?
Code: Select all
function love.load()
state = "menu" -- start the game in the menu state
end
function new_game()
-- do stuff
state = "game"
end
function love.draw()
if state == "menu" then
-- draw menu
elseif state == "game" then
-- draw game
end
end
-- et. c.
Re: main menu questions (buttons, loading other .lua files e
Yeah I was doing, thanks, i'll move it now and give it a shotSounds like you're setting the fps variable in love.load() or in the global scope. Try putting that bit of code in love.update().
I don't think I worded it correctly, but yeah, basically instructions for how to manually check the mouse positions to see if they're in the 'button' area. I didn't mean like proper buttonsIt isn't as easy as "just do this" unless you want to download something and use in your project.
To do buttons without any third-party libraries, you'd have to manually check mouse positions and see if they are within a certain area of the screen, and then draw a corresponding image.
That makes sense, but I basically want my game split into different files so that if I want to edit a specific part later, i can just load up 'inventory.lua' for example.Make your love.update and love.draw callbacks do different stuff depending on what "state" the game is in. Something like this:
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: main menu questions (buttons, loading other .lua files e
From your posts, I can see that you need some understanding of Lua and programming in general before you do things like that. That's not a bad thing, but you need to realise that something like "basically instructions for how to manually check the mouse positions to see if they're in the 'button' area." requires nothing more than basic programming skills (or in fact basic math skills).
Help us help you: attach a .love.
Re: main menu questions (buttons, loading other .lua files e
I understand how to do it, just thought it'd help if there were a tutorial on it
And yeah, I'm still in the learning process, hence why I chose LOVE over SDL or Irrlicht or something Everyone's gotta start somewhere, and I'm using LOVE as my learning project. I have coded C++ applications in the past
EDIT: And that's what forums are for are they not? Asking questions and learning things? And thelinx has been very helpful, moving the FPS and deltatime worked perfectly, so my debug menu is working now
On another note, whenever I use love.graphics.newFont, either in love.load or anywhere else, even if I just set the size, I get a massive memory leak, and my fps drops to 3. Without using love.graphics.newFont anywhere, I get 45fps minimum. Is this a bug? It was mentioned in the bug tracker before.
And yeah, I'm still in the learning process, hence why I chose LOVE over SDL or Irrlicht or something Everyone's gotta start somewhere, and I'm using LOVE as my learning project. I have coded C++ applications in the past
EDIT: And that's what forums are for are they not? Asking questions and learning things? And thelinx has been very helpful, moving the FPS and deltatime worked perfectly, so my debug menu is working now
On another note, whenever I use love.graphics.newFont, either in love.load or anywhere else, even if I just set the size, I get a massive memory leak, and my fps drops to 3. Without using love.graphics.newFont anywhere, I get 45fps minimum. Is this a bug? It was mentioned in the bug tracker before.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: main menu questions (buttons, loading other .lua files e
love.graphics.newFont returns a new font object, so you should never do it outside of love.load. I would recommend doing something like this:ntpspe wrote:On another note, whenever I use love.graphics.newFont, either in love.load or anywhere else, even if I just set the size, I get a massive memory leak, and my fps drops to 3. Without using love.graphics.newFont anywhere, I get 45fps minimum. Is this a bug? It was mentioned in the bug tracker before.
Code: Select all
function love.load()
fonts = {
small = love.graphics.newFont(11),
medium = love.graphics.newFont(16),
large = love.graphics.newFont(22)
}
end
function love.draw()
love.graphics.setFont(fonts.large)
love.graphics.printf("Look, ma! No memory leaks!", 0, love.graphics.getHeight()/2, love.graphics.getWidth(), "center")
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: main menu questions (buttons, loading other .lua files e
Yes, you are right here.ntpspe wrote:EDIT: And that's what forums are for are they not? Asking questions and learning things? And thelinx has been very helpful, moving the FPS and deltatime worked perfectly, so my debug menu is working now
The thing is, the forums can only help you if you have specific questions or problems. To check if the mouse is within a certain area, I could tell you to use love.mouse.getPosition, but you should be able to think of a way to compare that location to some other numbers. See Programming in Lua if you don't know the right syntax.
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: main menu questions (buttons, loading other .lua files e
The fastest, easiest way that I can think of would be to make a new file called game.lua or something, which contains love.load, love.update, love.draw, and all the other functions you want. Then, to start your game, use the codentpspe wrote:3. When the user clicks 'New Game' is there some way for it to move from main.lua to... game.lua or something? So that I can have the main.lua as the menu and for global variables, and then the main game will be in another .lua file?
Code: Select all
love.filesystem.load("game.lua")() love.load()
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: main menu questions (buttons, loading other .lua files e
Thanks Taehl I managed to do that last night and it all works fine
@Robin yeah, Well I've managed to get button detection working by creating 4 variables, x1, x2, y1 and y2, which set the boundary for the 200x100 button.
So basically,
Which works perfectly
@Robin yeah, Well I've managed to get button detection working by creating 4 variables, x1, x2, y1 and y2, which set the boundary for the 200x100 button.
So basically,
Code: Select all
function love.mousepressed(x ,y ,button)
if button == "l" and x > spbuttonx1 and x < spbuttonx2 and y > spbuttony1 and y < spbuttony2 then
buttontest = "You clicked the singleplayer button"
singleplayer()
end
end
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot], Google [Bot] and 12 guests