Jump to content

Game loops, Menus

- - - - -

  • Please log in to reply
2 replies to this topic

#1
stashed

stashed

    Newbie

  • Members
  • Pip
  • 1 posts
Hello, I'm creating a game in 2D and I'm trying to find guidelines on how to manage the loops. I do not know where I'm supposed to put the loop for the logic and rendering, yet having the functionality to pause the game by for example pressing ESC to bring up a menu. And this menu, how do I create one with custom made buttons etc.

For some reason what I just wrote doesn't make much sense to me, I find myself in the situation where I do not know where to start. Help please.

Also I am working with actionPerformed, but WHAT is an action here? When does an action happen?

Note: I've programmed in C++ before and Java is rather confusing at first glance.

#2
nicckk

nicckk

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 629 posts
You may want to look into the MVC design method. Java: Model-View-Controller (MVC) Structure

#3
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
If you are not doing event based programming which java is and assuming for simplicity that you don't have threads,

then your program at any given point is following one sequence of instructions. If you put a loop there which is printing some thing on 2D and want to display a menu with escape, you should have a check for key board press and test if it is escape in side that loop which does it in every iteration, breaks from loop and jump to escape menu code if key is matched.

For the latter part of your question, you first add an Action Listener (from code or GUI) which as name tells is listening for an event to occur. What ever action performed behavior you attach to that listener would be performed when the event has occurred.

Java is event driven so the code to interrupt a running program and pass it to your event handling function is transparent to you and appears as simple as dragging and dropping a button to your GUI, double click on button to open up it's button pressed event and write code there which will execute when button is pressed.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users