Help with a black screen when exiting out of my lobby [closed]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
bobbymcbobface
Citizen
Posts: 51
Joined: Tue Jun 04, 2019 8:31 pm

Help with a black screen when exiting out of my lobby [closed]

Post by bobbymcbobface » Mon Oct 21, 2019 10:30 am

So here's the problem -

1. whenever i go to progress over to the lobby a black screen appears
1a. I'm guessing this is because the object I'm drawing is no longer being drawn in "sprite.lua" because the condition needed to draw it is not met

2. Can you also help me tidy up the code a bit since I'm calling my collision for other objects in sprite.lua and i don't think that's right

Thank you in advance

Game.love


--Removed--

edit: to activate the black screen move across the top wall until you hit the right block (it's in the middle)
Last edited by bobbymcbobface on Thu Nov 07, 2019 5:15 pm, edited 3 times in total.
I make games that run on potatoes :P

User avatar
pgimeno
Party member
Posts: 1871
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: Help with a black screen when exiting out of my lobby

Post by pgimeno » Mon Oct 21, 2019 11:17 am

bobbymcbobface wrote:
Mon Oct 21, 2019 10:30 am
So here's the problem -

1. whenever i go to progress over to the lobby a black screen appears
When lobbyexit changes from 0 to 1, lobby:draw is no longer called in introhandler.lua. lobby:draw draws everything, so it's no surprise that you get a black screen.

bobbymcbobface wrote:
Mon Oct 21, 2019 10:30 am
2. Can you also help me tidy up the code a bit since I'm calling my collision for other objects in sprite.lua and i don't think that's right
First and foremost, use a state library! Or write your own; I give some hints on how to do it here: https://love2d.org/forums/viewtopic.php ... 26#p194226

Second, get rid of globals. You use many globals for managing states, so you should need far fewer after you start using a state library. But getting rid of them will help you keep your code much tidier. A possible exception is the states table itself.

User avatar
bobbymcbobface
Citizen
Posts: 51
Joined: Tue Jun 04, 2019 8:31 pm

Re: Help with a black screen when exiting out of my lobby

Post by bobbymcbobface » Mon Oct 21, 2019 2:02 pm

Thanks! I'll give this a try
I make games that run on potatoes :P

User avatar
bobbymcbobface
Citizen
Posts: 51
Joined: Tue Jun 04, 2019 8:31 pm

Re: Help with a black screen when exiting out of my lobby

Post by bobbymcbobface » Wed Oct 23, 2019 8:55 am

ok i tried your example and while i do understand (partially) what to do i can't work out where i need to put the table implementation without it raising an error with lobby.lua saying it's in a continuous loop - mind providing a short example of how it would be applied into my code, thankyou (but you don't need to implement it into the whole thing - I'm not asking you to do my code of course :) just need it in a partial bit of it implemented into my code so i see how it works)
I make games that run on potatoes :P

User avatar
pgimeno
Party member
Posts: 1871
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: Help with a black screen when exiting out of my lobby

Post by pgimeno » Wed Oct 23, 2019 2:25 pm

OK, there's a lot of work because things from one screen are spread into various files. In particular, many things that belong in the menu or in the game, are actually in introhandler.lua.

This is what the new file states.lua would contain:

Code: Select all

local function activate(self, new)
    assert(new, "Attempt to activate a state that does not exist yet")
    if self.active and self.active.when_deactivated then self.active:when_deactivated() end
    self.active = new
    if new.when_activated then new:when_activated() end
end

return {activate = activate, active = false}
This is how main.lua would look like:

Code: Select all

--[=====[-------------- Modules --------------]=====]--
local states = require 'states'

love.window.setFullscreen(true, "desktop")

--[=====[-------------- Events --------------]=====]--
function love.load()
    states.introh = require 'introhandler'
    states.menu = require 'menu'
    states.info = require 'info'
    states.game = require 'game'

    for k, v in pairs(states) do
        if type(v) == "table" and v.load then v.load(args) end
    end
    states:activate(states.introh)
end

function love.update(dt)
    if states.active.update then states.active:update(dt) end
end

function love.draw()
    if states.active.draw then states.active:draw() end
end

function love.keypressed(...)
    if states.active.keypressed then states.active:keypressed(...) end
end
Remember to add more events if you need them.

You need to create two new files, one for the info screen and one for the game. From the code, it seems to me that you want to have a pause menu; if so, maybe you need a new file for it, or maybe you can do with the existing menu. I've used the latter approach below.

You need to move all code that belongs to the menu (the code that you have in introh.lua under 'if state == "menu" then ...'), to menu.lua. The variable mclick would be in menu.lua as well. The variable 'Info' is not necesary. The variable 'music' is unused because the code is commented out, but it looks like it belongs in menu.lua.

introhandler.lua has no business updating anything other than the splash screen, therefore sprite:update(dt) would be moved to game.lua.

introhandler.lua ends up looking like this:

Code: Select all

--[=====[-------------- Modules --------------]=====]--
local o_ten_one = require "o-ten-one"
local states = require 'states'
local menu = require 'menu'

--[=====[-------------- Variables --------------]=====]--
local introh = {}

--[=====[-------------- Events --------------]=====]--

function introh:load()
    splash = o_ten_one({fill = "lighten"})
    function splash.onDone()
        menu:mainmenu()
    end
end    


function introh:update(dt)
    splash:update(dt)
end


function introh:draw()
    splash:draw()
end


function introh:keypressed(key)
    if key == "escape" then
--        splash:skip() -- slow to react!
        menu:mainmenu()
    end
end


return introh
Isn't that clear and tidy?

The variables menuon, menuallow, allow are no longer necessary and can be removed.

The idea is that every file that handles a state takes care ONLY of what is necessary for that state. This keeps the code a lot tidier. When switching states, instead of setting the variable 'state', you use states:activate(states.NEW_STATE). In the case of the menu, instead of doing that, you use menu:mainmenu() for the main menu, and menu:pausemenu() for the in-game pause menu (that will set up the variables to show the correct menu; remember to first do: local menu = require "menu" in the file that calls the menu).

I've attached a .love file with a new states.lua library, new files info.lua and game.lua, and my changes to main.lua, introhandler.lua and menu.lua. Note that the game crashes when it calls menu:allow() because that doesn't exist any longer. You probably want to use states.game:setroom(new room name) instead, which is a function that I have created that I think you might find useful later. That makes the variable 'lobbyexit' unnecessary. You will probably need to clean up some stuff that you were using for handling the states in the way you were doing it.

I think you could use a similar approach for rooms (or maps, if you prefer) as for states; however I haven't implemented that.

The player moves more slowly because you were calling sprite:update(dt) twice, one in main.lua and one in introhandler.lua, and now it is called only once. I think that calling it twice was a bug, so you may need to adjust the player speed.

I've got rid of the 'delay' variable because I wasn't sure what it was for.
Attachments
Game-with-states.love
(7.16 MiB) Downloaded 12 times

User avatar
bobbymcbobface
Citizen
Posts: 51
Joined: Tue Jun 04, 2019 8:31 pm

Re: Help with a black screen when exiting out of my lobby

Post by bobbymcbobface » Thu Oct 24, 2019 10:07 am

thanks! this has provided a great help to me and i understand what you mean about states now - again thanks alot :)
I make games that run on potatoes :P

User avatar
bobbymcbobface
Citizen
Posts: 51
Joined: Tue Jun 04, 2019 8:31 pm

Re: Help with a black screen when exiting out of my lobby

Post by bobbymcbobface » Sun Oct 27, 2019 11:26 am

ok hopefully the last problem to come across for some reason the map is not being drawn or in that matter even called is there a piece of code I'm not activating or are my functions incorrect? - thankyou for putting up with my endless questions :)
I make games that run on potatoes :P

User avatar
pgimeno
Party member
Posts: 1871
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: Help with a black screen when exiting out of my lobby

Post by pgimeno » Sun Oct 27, 2019 8:50 pm

bobbymcbobface wrote:
Sun Oct 27, 2019 11:26 am
ok hopefully the last problem to come across for some reason the map is not being drawn or in that matter even called is there a piece of code I'm not activating or are my functions incorrect? - thankyou for putting up with my endless questions :)
It was drawn in the version I posted. Do you mean the black screen when exiting the lobby?

If so, what map do you expect to be drawn? I haven't seen any map other than the lobby, therefore the problem to me was that there weren't any other maps created yet.

User avatar
bobbymcbobface
Citizen
Posts: 51
Joined: Tue Jun 04, 2019 8:31 pm

Re: Help with a black screen when exiting out of my lobby

Post by bobbymcbobface » Mon Oct 28, 2019 8:41 pm

ah sorry didn't specify that - it's in map.lua and i think it's the command is map:load() though i don't know why whenever i got to the lobby it either throws an error or does nothing at all or as usual throws a black screen at me

Edit! ok i managed to draw the map in the example below all the help i need now is to remove the collisions from the lobby


--removed--
Last edited by bobbymcbobface on Wed Oct 30, 2019 12:56 pm, edited 2 times in total.
I make games that run on potatoes :P

User avatar
pgimeno
Party member
Posts: 1871
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: Help with a black screen when exiting out of my lobby

Post by pgimeno » Tue Oct 29, 2019 10:46 am

bobbymcbobface wrote:
Mon Oct 28, 2019 8:41 pm
Edit! ok i managed to draw the map in the example below all the help i need now is to remove the collisions from the lobby
An easy way is to create a new bump world when you exit the lobby, and let GC clean up the old one. You need to add the player again to the new world, of course.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests