• Post Reply Bookmark Topic Watch Topic
  • New Topic

Asteroid's game issues: flickering window, and objects not moving correctly

 
Michael L Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,

I am very new to this forum (about 15 mins.) and I am a second term java student in college so I don't know nearly enough to be tackling this game but I figured I would test myself out a little bit. I am really really struggling with a couple of issues I am having with this game and so far I don't know where else to turn.
I am very grateful for sites like this one as I have come here in the past for help. Okay to the issues at hand. I don't know why or how (I have an idea on why) but when I load this game up it flickers like mad. Right now my target frame rate is set to 60fps and I am floating right around there right now (around 62-65 fps) and I am triple buffering using the BufferStrategy in the Canvas class. I completed my game engine last night so maybe I missed something? But as far as I can tell I don't think that is what's causing the flicker. Also, I checked my math, but the asteroids themselves are flying into the screen at warp speed, however, some are not. The movement of asteroids is choppy to say the least and I can not move my ship (which I will discuss later if I can figure out these issues first. I have tried everything under the sun as far as moving things around but I am at a loss. Currently all of my updating takes place in my render() method and paint() draws the image while update() calls paint(). All of the updating for the objects, the gameUpdate() method, takes place in my tick() method for the frame rate. I am hoping that this makes sense to you all and I am giving you a look at those methods including the threads. I would upload the whole code but I don't know what the policy is for that. If you need more code in order to help me then I will for certain upload more. Thank you so much everyone for your help. I am just at a loss with this and I have no idea how to get it to work. I just need this to work at a basic level before I can start my sprite sheets. Thank you all again for your time, I know it is valuable.

Michael Smith

Here is my game engine, the render() is at the bottom along with the tick(). The start(), run() and stop() are inlcuded as well:



Here is my paint() and update() methods:




Thank you again guys for your help. Once again I can upload the entire driver class (Asteroids.java) but it is about 400 lines of code and I don't want to overwhelm anyone (or tick anyone off).
 
Tony Docherty
Saloon Keeper
Posts: 3142
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the code posted I'm not sure what your problem is but I have noticed in your render method you create a graphics object which is stored in a variable g2d which is local to the render method and in your tick method you are using a graphics variable g2d which must be an instance variable (as I can't see a declaration anywhere) so this is not the same object as your are creating in your render method.
 
Michael L Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to fix the program and get it to work. It amazes me that I made the mistakes I made but I am grateful for the response here and the internet. Now it is functioning and working! I just need to get the bullets to fire in the proper direction. Thank you to all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!