Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 1225 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.

http://slick.cokeandcode.com

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!

http://wiki.java.net/bin/view/Games/JeffFAQ
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 Member


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.

-JAW
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (36 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (41 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (35 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!