Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Performance trouble  (Read 2005 times)
0 Members and 1 Guest are viewing this topic.
Offline Melvin Frohike

Junior Newbie

« Posted 2007-04-04 19:37:27 »

Hi everyone,
I am currently writing a RISK like strategy game. The game mechanics work nicely, but unfortunately the graphics are very slow.

The World map consists of lots of two-dimensional polygons, that can have three or more vertices. Each polygon represents a sector.
I am using Graphics2D. First, all polygons are drawn using fillPolygon in a color that represents the nation that owns the sector.
 To make the game look a bit nicer, i use a 12 pixel wide Stroke and draw the Polygon in a translucent black. this time with drawPolygon. Next, i set the stroke back to 1 and the color to a solid black and draw the polygon again with drawPolygon, to show the borders.

There is more to it, but this part of the code is, what slows the game down.
I helped myself by buffering the worldmap in a BufferedImage and only redrawing it when the world map changes. But as soon as a sector gets conquered, the world map has to be redrawn and the game slows down.

Do you have any suggestions, how to improve performance?

Sorry for my bad english.
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #1 - Posted 2007-04-04 20:33:20 »

Put the borders (with antialiasing) in one image (only once). Use another one for the colors (without antialiasing). After an update draw the changed region of the color and border image into a 3rd buffer.

Note that you have to clear the first image (the border one) manually before drawing the country borders. The reason for that is that freshly created images are only completely transparent on windows (well, duh... shit happens).

This should be a lot faster, I think.

弾幕 ☆ @mahonnaiseblog
Offline Melvin Frohike

Junior Newbie

« Reply #2 - Posted 2007-04-07 13:38:17 »

thanks a lot.
that tipped me into the right direction.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder

Got any cats?

« Reply #3 - Posted 2007-04-10 19:34:04 »

It would probably mean starting from scratch, but in this day and age you might want to look at a OGL based 2D engine  like Slick.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Offline ddyer
« Reply #4 - Posted 2007-04-28 21:04:24 »

Rather than drawing very complex maps using graphics, using a big image is simple, fast, and allows
arbitrary complexity.   Jepg images of maps compress really well.  Your programming problem then becomes
matching the arbitrary images to the internal game logic "where is france?" for example.  A useful trick is to
use another image for this purpose - and assign a unique color to each significant feature - but don't use
JPG images as you can't rely on the colors being rendered exactly as your expect.
Offline JAW

Senior Devvie

Medals: 2

« Reply #5 - Posted 2007-05-04 12:52:10 »

Java 2D drawing always seems a little slow to me. Bitmask transparency is ok, but full Alpha really slows things down. I prefer to precompute images whenever possible. I had an idea about a game playing at night or using fog, using tiles. More distant tiles should be darker or foggier.

First I used a tile image and a fog image and draw the fog image over the tile using Alpha. It was pretty slow. On second try, I generated 5 degrees of fogginess for each tile only once by combining tile and fog with different alpha and storing the results. Its faster, but takes 5 times more memory. Its a tradeoff.

Generally speaking, you should always try to render transparency only once and store the result. On 30fps or more its a difference when you compute it always once and then reuse it the other 29 frames. I once thought about creating a special layer for effects and dynamic elements, a bitmask transparent image which will be drawn over more static background.

Instead of using Alpha you can render the transparency once and then overlay the original background with the computed image. Drawing 2 non transparent images is faster than drawing alpha.

Pages: [1]
  ignore  |  Print  

EgonOlsen (76 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (256 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (157 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!