Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / I have a problem with menu (programmed with Dark GDK)

Author
Message
WKvc
13
Years of Service
User Offline
Joined: 15th Jul 2011
Location:
Posted: 10th Oct 2011 21:52
I need help. I'm working on a very important project and I encountered a problem when making the main menu.

After starting the game all the files are loaded correctly. But when using the arrow keys on the keyboard trying to change the menu option, then there is a problem.

After pressing the DOWN KEY option pointer jumps to the selected option, but a moment after he returns to the original settings. This is shown in the Annex (the menu is in Polish. Nowa gra - new game. Wczytaj - load game,Wyjdź - exit).

And this is my code. Main CPP file:


And this is Menu.h file:

Attachments

Login to view attachments
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Oct 2011 15:09
Not a C++ expert, but I believe the downkey is still being pressed when you reach the RESUME label; so the program sends the focus back to the original menu.

What you probably need is a [key up] event, which requires a little manual labour.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Oct 2011 23:49
The program is not structured well, you need to redesign it. Think about it that the execution of the game loop is circular, not linear. "while (LoopGDK())" is a loop, which is repeatedly calling the Menu function, about 60 times per second. The "if(dbDownKey())" statement will not just stop either and wait until you press something, instead, if you don't press a key, it continues through to the end of the Menu function, then gives control back to the main loop. Then the Menu function is called again and the first thing it does, is that it sets the pointer sprite back to its original position (dbSprite). You could set a breakpoint and follow the code execution sequence with the debugger step by step to see where it's going.

At present unfortunately I don't have time to write some better design for you, so I can only give some quick advice.

Don't load your sprites from disk every loop, meaning: do not call the MenuItems function from the Menu function. Initialization should be done before "while (LoopGDK())", or it should be done in a system of game states which guarantees that you load assets from disk only once.

You don't need to delete a sprite to reposition it with dbSprite. It works without deletion, dbSprite will just change the coordinates if the sprite already exists.

Do not use "goto" labels in C++. It may work but the program resembles BASIC more than C++ and may lead you to false assumptions about what gets executed when. The task can surely be solved with better code organization, e.g. with switch statements.

What Chris said is also true: dbDownKey returns 1 as long as the key is held down. You might want to introduce a boolean variable to track when the key is released, because if the key down event is continuously triggered, it might be difficult to stop the cursor on a certain button.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 2nd Nov 2011 23:16
I disagree with this blanket statement - because goto shouldn't be used much if at all.. to say never means you can't optimize long logic trees by circumventing code that doesn't need to be executed.

"Do not use "goto" labels in C++" 98% of the time this is good advice - but never might be a little strong perhaps.

Stephen Young
16
Years of Service
User Offline
Joined: 23rd Feb 2008
Location: UK
Posted: 3rd Nov 2011 00:05 Edited at: 3rd Nov 2011 00:12
Yeah this is a very inefficient way of doing it. Just make a variable to store what menu item is selected. var = 0(Load), var = 1(resume), var = 2(exit).

Then when the player presses the UP key, var--; or if they press down key, var++;



ect.

Login to post a reply

Server time is: 2024-11-19 06:33:02
Your offset time is: 2024-11-19 06:33:02