Need some help in using hump

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
teagrumps
Prole
Posts: 6
Joined: Sat Mar 15, 2014 4:19 pm

Need some help in using hump

Post by teagrumps »

Hi all,

I want to have some states in my game such as 'menu', 'options', 'help' etc. The idea is to load a splash screen initially and continue from there based on player input. I looked around the forum and decided on hump to achieve 'state' function in my game. But I don't think i'm doing it right love doesn't load the splash screen. Here' my code in my main.lua. Any help is appreciated. Thank you :)

Code: Select all

menu = {}
function menu:init() --loading and drawing a splash screen
    splash = love.graphics.newImage("splash.png")
end

function menu:draw()
    love.graphics.draw(splash, game_width, game_height)
end

function love.load()
    Gamestate.registerEvents()
    Gamestate.switch(menu)
    bg = {0,153,76}
    love.graphics.setBackgroundColor(bg)
end

User avatar
MGinshe
Prole
Posts: 31
Joined: Sun Apr 17, 2011 3:50 am
Location: New Zealand

Re: Need some help in using hump

Post by MGinshe »

first off, love.graphics.setBackgroundColor only accepts numbers so you'll have to use unpack() on your bg table:

Code: Select all

function love.load()
    Gamestate.registerEvents()
    Gamestate.switch(menu)
    bg = {0,153,76}
    love.graphics.setBackgroundColor(unpack(bg))

    -- lua will see this as love.graphics.setBackgroundColor(0,153,76)
end 
second, all positions in love2d start at the top-left. this means that your call to love.graphics.draw is drawing the top-left corner of the image at the bottom-right of the screen. try this:

Code: Select all

function menu:draw()
    love.graphics.draw(splash, 0, 0) -- 0,0 is top left, screenw,screenh is bottom right
end
hopefully this helps :)
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Need some help in using hump

Post by DaedalusYoung »

MGinshe wrote:first off, love.graphics.setBackgroundColor only accepts numbers so you'll have to use unpack() on your bg table:
No, it can also accept a table.
User avatar
MGinshe
Prole
Posts: 31
Joined: Sun Apr 17, 2011 3:50 am
Location: New Zealand

Re: Need some help in using hump

Post by MGinshe »

the more you know. thanks for pointing that out.
teagrumps
Prole
Posts: 6
Joined: Sat Mar 15, 2014 4:19 pm

Re: Need some help in using hump

Post by teagrumps »

It works!! (doing a happy dance right now)
Thank you so much :D
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests