-1

I have been making a 2d fighting game in java over the last few months but have always had the same annoying issue that after a few times of closing and re running the game, it will always suddenly drastically slow down to a set speed/frame rate. This happens on my not so great laptop as well as my gaming pc so I don't think it's a performance issue.

For some reason it is also related to when I start up my computer, as if I restart my computer it will run smoothly, and then soon after when I run it again it will go back to running in slow motion.

I am using swing timers and a paintComponent method to create the game.

Thanks

JackGoodwin
  • 39
  • 1
  • 3
  • You know there is a lot of things can be. Static Variables, an infinite Loop, A thread that is not closing, You are creating objects but not letting that the GC destroy it. It's to broad your question. Try debuggin, use JProfiler, etc. – Gatusko Feb 22 '17 at 13:31
  • Too many possible reasons. It could even be because you are sleeping your in you event dispatch thread. Or you are doing too many things which you shouldn't do in your paintComponent() method giving you an illusion that it is lagging or irresponsive. It could be your inefficient logic, too many nested loops and etc.. – user3437460 Feb 22 '17 at 15:32
  • You'll need to [profile](http://stackoverflow.com/q/2064427/230513) you code to learn more. – trashgod Feb 22 '17 at 17:22

1 Answers1

0

Profile the code. A profiler can help you find memory leaks and hotspots. JProfiler is good but you have to pay for it. I use VisualVM

Jayfray
  • 415
  • 3
  • 12