Page 1 of 1

Need some help in using hump

Posted: Sun Mar 23, 2014 10:48 pm
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


Re: Need some help in using hump

Posted: Mon Mar 24, 2014 2:25 am
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 :)

Re: Need some help in using hump

Posted: Mon Mar 24, 2014 2:45 am
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.

Re: Need some help in using hump

Posted: Mon Mar 24, 2014 3:35 am
by MGinshe
the more you know. thanks for pointing that out.

Re: Need some help in using hump

Posted: Mon Mar 24, 2014 6:17 pm
by teagrumps
It works!! (doing a happy dance right now)
Thank you so much :D