Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Fullscreen performance question  (Read 2044 times)
0 Members and 1 Guest are viewing this topic.
Offline masterludo

Senior Newbie




Java games rock!


« Posted 2003-03-07 10:41:01 »

Hi *,

I don't know very well this new full screen concept and I have a question.
I'm trying to implement a soccer game, for which I have to draw first the pitch and then the player (only one for now). I use double buffering (at least I think I'm doing so  Wink) to do this, and there's no problem if I put the display mode at 640x480. But when I put it to 800x600, it's then much slower, even if I shorten the sleep time of the redrawing thread.
Thanks in advance!
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #1 - Posted 2003-03-07 10:44:43 »

A tip: to get good answer be sure to write good description on the problem.

Are you using Bufferstrategy? How much slower between the different modes? fps? etc..


Offline masterludo

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-03-07 10:54:31 »

I'm using BufferStrategy like from examples I could find and the fps dropped from 25 to 10.  Just ask if you need some more input, I don't know what I should exactly tell!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #3 - Posted 2003-03-07 11:30:09 »

Your fps is 25 in 640x400? It sounds like you are using operations that is not hardware accelated like scaling etc.

And then it sounds to me that the cpu has to work even harder when there are more pixels like 800x600 and therefor you get a big drop.

With my little 2d game library I got fps over 100 with 100 sprites moving on the screen and the in both 640x400 and 800x600.. I dont remember what 1600x1200 got but it was abow your fps anyway.

So can you post your render code, i.e the code where you are painting on your Graphic object, so that I can have a look on it.

I'm using BufferStrategy like from examples I could find and the fps dropped from 25 to 10.  Just ask if you need some more input, I don't know what I should exactly tell!

Offline masterludo

Senior Newbie




Java games rock!


« Reply #4 - Posted 2003-03-07 11:59:28 »

here's the code:

public void render() {
 Graphics g = getFrame().getBufferStrategy().getDrawGraphics();

 if (getFrame().getBufferStrategy().contentsLost()) {
   return;
 }

 if (null == getOffscreenImage()) {
   initBackBuffer();
 }

 Graphics2D offscreenGraphics = (Graphics2D)getOffscreenImage().getGraphics();

 // pitch position
 int tmpX = getPosition().getX();
 int tmpZ = getPosition().getZ();

 // pitch image is 1266x1694, we just need the frame's size
 Image img = ((BufferedImage)getPitchImage()).getSubimage(tmpX, tmpZ, FRAME_WIDTH, FRAME_HEIGHT);
 offscreenGraphics.drawImage(img, 0, 0, null);

 // draw the player
 // current player image returns an image stored in an array, corresponding to the running direction
 offscreenGraphics.drawImage(getCurrentPlayerImage(), getPlayerRelativeX(), getPlayerRelativeZ(), null);

 offscreenGraphics.dispose();

 g.drawImage(offscreenImage, 0, 0, null);

 getFrame().getBufferStrategy().show();
}
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #5 - Posted 2003-03-07 12:34:50 »

the trouble that I see is the

1  
2  
3  
   // pitch image is 1266x1694, we just need the frame's size
 Image img = ((BufferedImage)getPitchImage()).getSubimage(tmpX, tmpZ, FRAME_WIDTH, FRAME_HEIGHT);
  offscreenGraphics.drawImage(img, 0, 0, null);


part of the code. Using the getSubImage routine EVERY time the render method is being called will slow the down the game alot.

And using such a large image as a background is not optimal either. My suggestion is that you make the pitch as tiles, as most of the part is green I quess only on image with dimension of 64x64 or 32x32 should to to paint large part of the pit. The sidelines etc can have specific tiles in the same size. Then save the background tiles as

1  
Image[][] pit


Where pit[0][0] is the top right corner of the soccer pit. And remember only create each tile image ones and then use that tile Image objects refrence in your pit array to avoid massive memory usage.

Then you need some sort of conversion between the pit array images and the coordinates of the frame that needs to be displayed.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
// pitch position
//  int tmpX = getPosition().getX();
//  int tmpZ = getPosition().getZ();

// use instead
Point p = translate(getPosition().getX(), getPosition().getY());
int tmpX = p.x;
int tmpY = p.y;

public Point translate(int x, int y){
  return new Point((int) x/TILEWIDTH, (int) y/TILEHEIGHT,
}


Then you need to paint some tiles on your graphic object

1  
2  
3  
4  
5  
6  
7  
int x, y;
for (int i=tmpX; i<(SCREENWIDTH/TILEWIDTH+tmpX); i++)
for (int j=tmpY; j<(SCREENHEIGHT/TILEHEIGHT+tmpY); j++){
g.drawTile(pti[i][j], x, y);
x+=TILEWIDTH;
x+=TILEHEIGHT;
}


I hope you get the idea... you still need to compensate for the offset the translate function makes otherwise the pitch will move one whole tile every 64px or so. This code is not a working one and written in 5 min.. just to let you see the concept.

Offline masterludo

Senior Newbie




Java games rock!


« Reply #6 - Posted 2003-03-07 12:55:34 »

I see,  thanks a lot Backmask. The only problem is that I would need this image as a background as it contains also some details like crowd, ....
That with the tiles is a good idea and is easy to implement but it wouldn't like as nice as the pitch image.
I guess I'll have to find some workaroud for this.
Thanks a lot for your help!
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #7 - Posted 2003-03-07 13:05:24 »

Just make the crowed as tiles to and try to work them in to the array as well. Thinks tiles  Grin

I havn't had the time to fool around with scrolling tile backgrounds yet but there is a library by zparticle at his website.

http://www.scottshaver2000.com/

it contains the code for the scrolling things. Havn't look at it but I have seen a demo on the scrolling and it worked with a good fps. (see under library -> planetation -> Downloads - > library source.

Always glad to help a fellow java gaming programmer  Roll Eyes

Offline masterludo

Senior Newbie




Java games rock!


« Reply #8 - Posted 2003-03-07 13:11:22 »

hehe, just a question still:
would there be a way to get a subimage with more efficience than BufferedImage.getSubImage(....)?
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #9 - Posted 2003-03-07 13:14:08 »

I don't know any other way. But maybe someone in these forums can tell you if there is.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline masterludo

Senior Newbie




Java games rock!


« Reply #10 - Posted 2003-03-07 13:28:54 »

np m8! BTW, do you know how to mask some color from an image to get some kind of transparency by masking a specific color and how to change a color to an other one?
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #11 - Posted 2003-03-07 15:07:21 »

Hmm havnt tried anything like that...

I use ordinary .png or .gif files when I need transparasy on my sprites. I create them with the followning code..

1  
2  
3  
4  
5  
6  
7  
8  
GraphicsConfiguration gfxConfig = //get your gfx here

Image tempImage = new ImageIcon(filename).getImage();
BufferedImage sprite = gfxConfig.createCompatibleImage(tempImage.getWidth(), tempImage.getHeight(), Transparency.BITMASK);

Graphics2D g = (Graphics2D)sprite.getGraphics();
g.drawImage(tempImage, null, null);
g.dispose();

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.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (64 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!