• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Restart Button Java - Beginer  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone! I recently had started learning Java, also I made few tutorials about making games in Java (this is what I am interested in mostly). In one, there was a game which I had already have recreated in most, but there's one thing that I can't handle. It's Restarting game after death. I can't do it. I made keyListener at "VK_R" and if instruction, which is made only if state == GameState.Dead;. But I don't know that I need to write there. Maybe you could take a look and give me some advice? I know its rude to ask you for it, but if you don't want to help me that much (writing few lines ;)), then just tell me what to do And by the way, this is my first post, so Hello!

 
Bartender
Posts: 3321
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

That's a lot of code to read and with no description of what the game does etc it's hard to give specific advice. However, general advice is to reset every instance variable back to the state it would be in when the game first starts.
To reset the screen you should not be calling paint() directly, to force a paint to occur use repaint() instead.
 
Krzysiek Wąsowicz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, this is simple 2D game where you have life bar, health, your enemies also have it. You die when a) you are killed by them b) you fall. Enum GameState.Dead is launched when health = 0 or when player gets under some level (in program: 500 px under). I tried to bring repaint() but it doesn't work. I need to nullify all variables, but all Objects too? Like enemies, Player, background and Tiles?
 
Tony Docherty
Bartender
Posts: 3321
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes all objects need to have their state reset (or alternatively new objects can be created).

That is anything that is (or can be) changed during playing a game must be reset back to their initial state.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!