0

People said I was mad, people said I was crazy. They told me to use slick2d or lwjgl but i decided to make my game in swing so please don't tell me to use some libary, that would not answer my question.

Screenshot of my game Screen from my game

I am making a game in swing it is starting to become something :) you can see it here. I have good performance but i want to get the best possible performance with swing so can you give me some performance tips for making games in swing?

If someone would be kind enough to criticize my code (I'm fifteen so i don't have a teacher or anything so I would like to know if I am writing crap) then you can download the source here.

Thank you

P.S: I' m serious i know that slick2d uses opengl, that swing wasn't made for games so please don't try to convert me, i will use a library for my next project don't worry ;)

sanchixx
  • 275
  • 2
  • 5
  • 12
  • 3
    If you want someone to review your code, you're looking for [codereview.se] – Jim Garrison Oct 13 '13 at 07:11
  • Yes. This site is meant for specific technical questions. – Adam Oct 13 '13 at 07:11
  • I not here for that, but i will use it next time i just want tips for using swing in an efficient way. People can look at my code if thy want to. – sanchixx Oct 13 '13 at 07:12
  • Again, that's not a specific question. – Adam Oct 13 '13 at 07:13
  • 1
    An example of a specific question is: How to efficiently draw tiled images? – Adam Oct 13 '13 at 07:13
  • So I can't ask to get tips on using swing :( – sanchixx Oct 13 '13 at 07:14
  • 1
    "can I get tips" is too broad. If you can narrow it down for what in particular you want to improve then that might be appropriate. You're ALSO asking for people to look at your code. The Code Review site Jim linked to is your best bet for that. – Adam Oct 13 '13 at 07:17
  • Ok so improving performances in swing would be acceptable? – sanchixx Oct 13 '13 at 07:17
  • That's a question for google. Also look for how to get performance from Java in general. Look up profiling if you haven't yet. – Adam Oct 13 '13 at 07:20

1 Answers1

2

Quick things come to my mind is, use of VolatileImage in place of BufferedImage can be better. BufferedImage will not provide hardware accelarated operations, but VolatileImage can provide.

But you have to investigate this.

See: Java : VolatileImage slower than BufferedImage

Or google "BufferedImage vs VolatileImage"

Further I suggest reading on like GraphicsDevice, GraphicsConfiguartion to work with images compatible with device.

One more tip: If your game has frequently used time consuming math operations like cos, sin, sqrt, you may cache results of this operations when game loads. Caching means - store results of math operations in data structures like arrays or maps, when game need to perform these operations, game can lookup values of operations without performing again.

Community
  • 1
  • 1
nullptr
  • 3,320
  • 7
  • 35
  • 68