Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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  
  Faster tile creation  (Read 1126 times)
0 Members and 1 Guest are viewing this topic.
Offline weston

Junior Member





« Posted 2004-08-02 06:17:33 »

I'm writing a game framework that I will use for making java2D games (I will do an jogl or lwjgl version later, havn't decided which yet), and for tiled games I use all the tiles for a given location from a single image (rm2k chipsets actualy). Right now I am breaking this image into pieces when the level is loaded and storing all the tile images in a BufferedImage[][], this allows me to draw my maps plenty fast, but it takes a bit too much time to do the breaking it into tiles part. Is there a way where I can get similar rendering speeds without such a big load time? here is my code for breaking the image into tiles:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
private void createTileImages()
  {
    Graphics2D g2;
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    for (int row = 0; row < tileImages.length; row++)
    {
      for (int col = 0; col < tileImages[row].length; col++)
      {
        tileImages[row][col] = gc.createCompatibleImage(Game.TILE_WIDTH, Game.GAME_HEIGHT, Transparency.BITMASK);
        g2 = tileImages[row][col].createGraphics();
        g2.drawImage(image, 0-col*Game.TILE_WIDTH, 0-row*Game.TILE_HEIGHT, null);
      }
    }
  }


for(int i = 1; i > 0; i++)
{
System.out.println(i+" cups of java downed");
}
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2004-08-02 07:59:24 »

You draw the whole image each time. The version of drawImage which takes a target and a source rect should be somewhat faster.

drawImage

弾幕 ☆ @mahonnaiseblog
Offline weston

Junior Member





« Reply #2 - Posted 2004-08-02 08:43:03 »

Ok, I'll give that a try and see how it does. Tommorow I'm Leaving to New York for 10 days Grin so I won't be responding about the results any time soon Sad.

for(int i = 1; i > 0; i++)
{
System.out.println(i+" cups of java downed");
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dranonymous

Junior Member




Hoping to become a Java Titan someday!


« Reply #3 - Posted 2004-08-02 14:03:36 »

oNyx - Why is the other drawImage slightly faster?  I looked at the javadoc between the different methods and it doesn't seem to mention anything about it being faster.
Offline Abuse

JGO Coder


Medals: 10


falling into the abyss of reality


« Reply #4 - Posted 2004-08-02 14:30:40 »

Quote
oNyx - Why is the other drawImage slightly faster?  I looked at the javadoc between the different methods and it doesn't seem to mention anything about it being faster.


I would presume because that method is manually specifying the clip rectangle, where as your method requires the API to work it out for itself.

I wouldn't expect the difference between the two to be large however. (a few extra if's per image draw, thats all)

btw, why are you breaking the source image into tiles anyway?
I would imagine rendering 100s of different tiles should be slower than rendering many different portions of the same image.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline pepe

Junior Member




Nothing unreal exists


« Reply #5 - Posted 2004-08-02 14:37:20 »

afair, Trembovetski said one time that using getSubimage(int x, int y, int w, int h)  on a BufferedImage would return an object pointing on the same source data.
I expect that to be way faster to draw under GL pipeline (no texture switching) but i think it might also help actually.
Moreover, it would reduce memory consumption, fragmentation in ram and vram, and would give almost non perceptible tile creation time.
Worth a try, imho.

Home page: http://frederic.barachant.com
------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
Offline weston

Junior Member





« Reply #6 - Posted 2004-08-02 15:03:37 »

whether I draw hundreds of diferent tiles or different areas of a single source image, I'm still drawing 16x16 pixels so I thought the speed would be the same... that doesn't mean I think thats the best way of doing it though, thats why I was looking for a new way Grin Sounds like the alternate draw method or getSubImage() could work well, sad I won't be able to try for 10 days though, I'm leaving in about 15 minutes...

for(int i = 1; i > 0; i++)
{
System.out.println(i+" cups of java downed");
}
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.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!