Creating Splash Screen/Menu etc.

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.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Creating Splash Screen/Menu etc.

Post by Ryne »

Hi again!. I asked this question on another topic and Robin gave me an answer but I still found it confusing. I'm trying to figure out the easiest way to create a splash screen, a menu screen, and the overall game itself. Right now I have the basics for a game created and I currently only have the main.lua, as well as a conf.lua file. What I would like to happen is:

- On first run of the game the splash screen appears, probably with a pre-set animation or logo
- After the splash screen the basic menu appears. Right now I'm only interested in having a "Play Game" button.
- Once the "Play Game" button is selected it would load the game.lua(basically just my re-named main file)

I say the "easiest" way, but obviously if there is a slightly more difficult efficient way, then I'd love to hear that as well, thanks again guys!
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Creating Splash Screen/Menu etc.

Post by Robin »

Do you understand game states? If you do now, what you descriped above will be very easy. If not, we'll make sure you do. ;)
Help us help you: attach a .love.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Creating Splash Screen/Menu etc.

Post by Ryne »

I think that's the problem, I don't really understand gamestates in general. The way I would assume is the you would be able to program in such away to allow different LUA files to be on screen at different times, in the same way the "Main.LUA" is loaded at first launch. Though reading some of the game-state code suggests differently. Could anyone do a basic example?
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Creating Splash Screen/Menu etc.

Post by Robin »

Firstly: don't think of game states in terms of files. They are completely independent. Just like, say, stories and books. You read stories in books, but one book can contain multiple stories, and one story can span multiple books.

Do you know what finite-state machines are?

I'm not sure I can think of an appropriate metaphor for game states, but we'll get there! :P
Help us help you: attach a .love.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Creating Splash Screen/Menu etc.

Post by Ryne »

So basically you're saying that all game data/functions/variables would be in separate lua files, but the main file would still have to refer to those files to get what it needs? So that the Main File still contains a lot of code, but most is in separate files?

Like this?:

GAME LUA

Code: Select all

function love.load()
local f = love.graphics.newFont("assets/font/font.TTF")
end
MAIN LUA

Code: Select all

function love.load()
love.graphics.setFont(f)
end

What would be your suggestion to achieve what I need?
Last edited by Ryne on Fri Oct 29, 2010 9:30 pm, edited 1 time in total.
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Creating Splash Screen/Menu etc.

Post by Robin »

No, not at all. Look, you can put everything in main.lua, or you could split it up. It's up to you, really. The thing about state is not which “file” is “loaded”, but what functions you're calling. Functions that could be in main.lua or any other file, just as long you require()d it.
Help us help you: attach a .love.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Creating Splash Screen/Menu etc.

Post by Ryne »

Oh, I think I get what you're saying now. After refering back to the code you posted in the previous thread, and your explaination here. In a nutshell (using your code) it would look something like this:

Code: Select all


menu = {} 
function menu.update(dt)
    -- this would contain the keys for the menu
end

function menu.draw()
    -- this would contain everything related to the visual aspect of the menu
end

game = {} 
function game.update(dt)
   -- same goes here, except for the game aspect
end

function game.draw()
  -- game related drawing
end

-- and then either do something like
love.update = menu.update
love.draw = menu.draw
-- or something like
function love.update(dt)
    currstate.update(dt)
end
function love.draw()
    currstate.draw()
end
currstate = menu

one thing I'm curious of is, game.draw would contain all of the "draw" information that I currently have in my main file correct? Then the variable for love.draw swaps for game.draw thus drawing everything for the game? This would be the same for the menu as well? I think I understand it now. :)

EDIT: Everything worked great. Thanks again Robin!
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Creating Splash Screen/Menu etc.

Post by Robin »

Ryne wrote:one thing I'm curious of is, game.draw would contain all of the "draw" information that I currently have in my main file correct? Then the variable for love.draw swaps for game.draw thus drawing everything for the game? This would be the same for the menu as well? I think I understand it now. :)
I'm not sure what you're talking about here, but I'm happy that it all works. :)
Help us help you: attach a .love.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Creating Splash Screen/Menu etc.

Post by Ryne »

Sorry I made that sound more complicated than it actually was. I meant it like this:

- There is a separate ".draw" for each State, menu.draw, game.draw, whatever.draw.
- Then you set the variable love.draw = game.draw, or whatever one You want displayed.

That sounds right?
@rynesaur
User avatar
bartoleo
Party member
Posts: 118
Joined: Wed Jul 14, 2010 10:57 am
Location: Savigliano

Re: Creating Splash Screen/Menu etc.

Post by bartoleo »

Yes... I used gamestate 'class' from HUMP library
it's simple and very very very easy to implement
hump thread http://love2d.org/forums/viewtopic.php? ... hilit=hump
my project it's here http://love2d.org/forums/viewtopic.php?f=5&t=1933
Bartoleo
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests