Hi, I create a game. the game have main loop, that running all the game. I use the method KeyPressed of the GameCanvas, but when the main loop running, the KeyPressed method don't reacting. I can't check in the loop if any key pressed form anouther reasons. Anyone can help me? TIA.
You have to poll for user input inside the game loop. The flow control can not leave the loop while the game state is running. I don't know if you have tried it, but you can create functions to update, draw and poll user input, then call them inside the game loop. Are you using any framework/engine or just coding through Native j2me?
I can't poll for user input inside the game loop. the game loop stop running when the game is over, and I need to check the keyPressed event also after the game over. I just coding through Native j2me. What can I do? Thanks.
Is your game state based? Just create a method for polling user input, and call it in whatever state that is running currently.. The app is still running after the game is over, right?
A state is a kind of module of the game. It provides you flow management. You can create menu state, game state, game over state, etc. In simple words, It handles the current status of the flow control.
Since you are not using any engine/framework, I guess you have to make a framework, that can define states, yourself.. OR you can search for suitable j2me frameworks for games.. I do not code in j2me, so I dont have much idea about it.. But I made games in UDK, XNA, Android and AS3 so I can only guide you through generalized game development and flow control.
Ok' thanks. Only one more question. I have 2 Canvases in my game: menu and game. The display show first the menu. When the user click "start", i change the current canvas to game, and call the main loop. Like this: d.setCurrent(game); game.loop(); The result is: the game canvas doesn't shown and the menu canvas stuck. I guess the problem is that the display don't change the shown canvas until the main loop stopped. The main loop doesn't stopped because the game don't started, so the game canvas don't shown. Do you have any idea what can I do? TIA.
I was stuck in same situation once, in my early days of game programming.. My game flow wasn't switching to the Game state from menu state, no matter what I tried, it wasn't working.. At last it turned out that I was doing everything except to update the screen. I wasn't calling Draw method after switching the states, thus Screen was stuck with Menu graphics even when the game was in game state..
I cant say much about that, even if I look into your code I wont understand much because as I said I do not code in J2ME.. I can't be much of a help there mate. I suggest you look for an active J2ME community, they can provide you some real help.