Hello
I am having an issue on switching gamestates using hump. I can use the Gamestate.switch function when going from the splash screen to the main menu , but when i use the Gamestate.switch function to go from the main menu into the game it self nothing happens, it remains on the main menu but i can still use the quit feature.
any idea's on what the problem is ?
PS: i have tried to use the Gamestate.push function instead of switch but there was no change. Also if i disable the splash screen and make the main menu load up , i can then switch Gamestates and get into the game it self.
Hump Gamestate Freezing on switch function
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 9
- Joined: Sat Mar 01, 2014 10:37 pm
Re: Hump Gamestate Freezing on switch function
Give us a .LOVE file to dissect and help you out. Here's a tutorial on how to do it if you don't already know, scroll down a bit to "Create a .love-file" and follow the instructions.
https://www.love2d.org/wiki/Game_Distribution
https://www.love2d.org/wiki/Game_Distribution
-
- Prole
- Posts: 9
- Joined: Sat Mar 01, 2014 10:37 pm
Re: Hump Gamestate Freezing on switch function
Sorry for the late reply , i have been trying to create a .love file , 5 hours later i have managed to do it , although .... when i try open to .love file myself i only get a black screen , but hopefully for you it should load the menu and game up ..
- Attachments
-
- platformer.love
- (7.24 MiB) Downloaded 192 times
Re: Hump Gamestate Freezing on switch function
Basically the problem with your *.love file is that you made the first letter uppercase, it had to be "main.lua" not "Main.lua". That causes the black screen when starting from the file.
For the problem with the switch from menu to game :
I guess the problem is that the conditions ( if x> 871 and x< 1172 and y> 99 and y< 150 then ) aren't given. I tested to switch with press return ..
...and it worked ( there is a error with a tile inside your game and there are a couple more problems with your code btw. but I'm to lazy to list them here, sry :[ ).
For the problem with the switch from menu to game :
I guess the problem is that the conditions ( if x> 871 and x< 1172 and y> 99 and y< 150 then ) aren't given. I tested to switch with press return ..
Code: Select all
-- Menu.lua
function state:keypressed(key)
if key == "return" then Gamestate.switch(Gamestate.Game) end
end
Re: Hump Gamestate Freezing on switch function
The reason the .love file is funky is because Main.lua is capitalized in the zip file, which makes it black out when you try to run it, so I renamed the file so that the "M" is not capitalized
Anywho, the game itself is.. odd. No offense, but it's very rough. Moreso, I don't use (a lot of) external libraries so I couldn't tell you exactly why this problem is happening, but I do have a solution! It looks like the problem is coming specifically from
If you change "timer < 0" to "timer > 0", state changing should work. Sorry I can't explain exactly why this is happening, my guess is that the gamestate is switched before HUMP is allowed to do its thing (since the game state changes on the first available frame).
I also made it so that you can see the button in question (I couldn't see any buttons being on the menu making it even more difficult to work with), so if you check it out you will notice some things have been changed. No worries though - the thing you needed help with is fixed.. although the game crashes immediately when you go to the "game" state.
On a side note now I have to upload this file outside of the forums since it's now somehow 14mb - larger than the max file upload limit -somehow. How did you upload this originally?! Did you.. compress the .zip? Shameful!
RRG. Uploading stuff online is so difficult, I just compressed the awesome Ocarina of Time music to fit to 10mb
Anywho, the game itself is.. odd. No offense, but it's very rough. Moreso, I don't use (a lot of) external libraries so I couldn't tell you exactly why this problem is happening, but I do have a solution! It looks like the problem is coming specifically from
Code: Select all
if timer < 0 then
Gamestate.switch(Gamestate.Menu)
end
I also made it so that you can see the button in question (I couldn't see any buttons being on the menu making it even more difficult to work with), so if you check it out you will notice some things have been changed. No worries though - the thing you needed help with is fixed.. although the game crashes immediately when you go to the "game" state.
On a side note now I have to upload this file outside of the forums since it's now somehow 14mb - larger than the max file upload limit -somehow. How did you upload this originally?! Did you.. compress the .zip? Shameful!
RRG. Uploading stuff online is so difficult, I just compressed the awesome Ocarina of Time music to fit to 10mb
- Attachments
-
- platformer.love
- (7.24 MiB) Downloaded 177 times
Re: Hump Gamestate Freezing on switch function
The actual problem is that you call Gamestate.switch() in love.update(). As the documentation states:
In consequence, this means that you switch to the menu state on every frame. If you want to switch three seconds after the game is loaded, you can for example use hump.timer:hump wrote:function registerEvents(callbacks)
Overwrite love callbacks to call Gamestate.update(), Gamestate.draw(), etc. automatically. love callbacks (e.g. love.update()) are still invoked.
Code: Select all
Gamestate = require 'hump.gamestate'
require 'Menu'
require 'Game'
require 'Splashscreen'
Timer = require 'hump.timer'
function love.load()
Gamestate.registerEvents()
Gamestate.switch(Gamestate.Splashscreen)
Timer.add(3, function() Gamestate.switch(Gamestate.Menu) end)
end
function love.update(dt)
Timer.update(dt)
end
-
- Prole
- Posts: 9
- Joined: Sat Mar 01, 2014 10:37 pm
Re: Hump Gamestate Freezing on switch function
Thank you very much guys !! I will take all your feedback and apply it to the game.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests