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

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

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

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

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

pgimeno
Party member
Posts: 2279
Joined: Sun Oct 18, 2015 2:58 pm

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

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.

bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

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

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

bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

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

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

pgimeno
Party member
Posts: 2279
Joined: Sun Oct 18, 2015 2:58 pm

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

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 --------------]=====]--
states.introh = require 'introhandler'
states.info = require 'info'
states.game = require 'game'

for k, v in pairs(states) do
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'

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

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

splash = o_ten_one({fill = "lighten"})
function splash.onDone()
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!
end
end

return introh

Isn't that clear and tidy?

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

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

bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

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

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

bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

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

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

pgimeno
Party member
Posts: 2279
Joined: Sun Oct 18, 2015 2:58 pm

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

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.

bobbymcbobface
Citizen
Posts: 78
Joined: Tue Jun 04, 2019 8:31 pm

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

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

pgimeno
Party member
Posts: 2279
Joined: Sun Oct 18, 2015 2:58 pm

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

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.

### Who is online

Users browsing this forum: No registered users and 13 guests