Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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  
  Graphics encoding help  (Read 1552 times)
0 Members and 1 Guest are viewing this topic.
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


« Posted 2009-01-01 18:16:12 »

I have some sprites that I want to add to my game. Currently they are stored as PNG but it takes too much space. I was looking at some source code from other games and I found the following one from Pitfall Scorpion Island:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
         // -- DECOMPRESS SPRITES BEGIN
        // -------------------------------------------------
        int[] spriteData = new int[1024];
         BufferedImage[][] sprites = new BufferedImage[10][2];
         String GRAPHICS_DATA = "\u1800\u1818\u1810\u1a18\u1c1e\u1818\u1818\u1818\u1818\u1818\u1c18\u1800\u1818\u1810\u3818\u3e3a\u183c\u1818\u1c1c\u7414\u4344\u0002\u1800\u1818\u1810\u1818\u1818\u1c1c\u1818\u0e1c\u3e0a\u2828\u0c08\u1800\u1818\u1810\u1818\u1c18\u181c\u1c18\u161e\u3432\u2224\u1020\u1800\u1818\u1810\u3818\u3e3a\u183c\u1c18\u363e\u6262\u80c3\u0080\u1800\u1818\u1810\u3e1a\u587c\u1858\u1e1c\u72da\u0033\u0000\u0000\u0000\ud870\u9288\ufac4\u3c78\u4933\u7000\u88d8\u8290\uf8c6\u3d78\u8532\u0000\u0000\u0604\u55ff\uffab\u8000\ubae0\u0b2e\u0303\uffab";
         for (int s = 0, dataIndex = 0; s < 10; s++) {
            int height = (s < 6) ? 11 : (s < 8) ? 6 : 5;
            int off = 0;
            for (int y = 0; y < height; y++, dataIndex++) {
               int data = GRAPHICS_DATA.charAt(dataIndex);
               for (int j = 0; j < 2; j++, off += 32) {
                  int row = data & 0xff;
                  data >>= 8;
                  int Y = (y << 1) + j;
                  for (int k = 0; k < 8; k++) {
                     int color = (row & 1) == 0 ? 0
                           : (s < 6) ? ((Y < 2) ? 0xFF887000
                                 : (Y < 5) ? 0xFFFC9838
                                       : (Y < 12) ? 0xFF80D010
                                             : 0xFF2A5F00)
                                 : (s < 8) ? 0xFFFFFFFF : 0xFF80FF10;
                     int off2 = off + (k << 1);
                     spriteData[off2] = spriteData[off2 + 1] = spriteData[off2 + 16] = spriteData[off2 + 17] = color;
                     row >>= 1;
                  }
               }
            }
            for (int i = 0; i < 2; i++) {
               int hi = height << 2;
               for (int y = 0; y < hi; y++) {
                  for (int left = y << 4, right = left + 15; left < right; left++, right--) {
                     int temp = spriteData[left];
                     spriteData[left] = spriteData[right];
                     spriteData[right] = temp;
                  }
               }
               BufferedImage image = new BufferedImage(16, hi,
                     BufferedImage.TYPE_INT_ARGB_PRE);
               image.setRGB(0, 0, image.getWidth(), image.getHeight(),
                     spriteData, 0, image.getWidth());
               sprites[s][i] = image;
            }
         }

         // -- DECOMPRESS SPRITES END
        // ---------------------------------------------------


It seems to me that this option uses lesser space but I didn't get how the code above works (specially the GRAPHICS_DATA constant).

Could someone explain it to me?

Or how is the best way to put sprites graphics instead of creating them using drawLine and similar functions?

Thanks for the help.
Offline bobjob

JGO Knight


Medals: 10
Projects: 6


David Aaron Muhar


« Reply #1 - Posted 2009-01-01 19:40:25 »

if the sprites are small why not use .gif?

My Projects
Games, Webcam chat, Video screencast, PDF tools.

Javagaming.org with chat room
Offline moogie

JGO Knight


Medals: 7
Projects: 5


Java games rock!


« Reply #2 - Posted 2009-01-02 05:54:27 »

There are a couple of sprite compression tools/ techniques for 4k competitions that have been created through out the years.

The two i know of are :

Ordered Index Differences compression tool

and

SuperPackME


The Ordered Index Differences compression tool is one i created for my 2007 entry ( http://www.java4k.com/index.php?action=games&method=view&gid=165 )

See http://www.java-gaming.org/topics/sprite-compression-tool/17876/view.html for details and downloads.


The SuperPackMe details can be found at http://jgcwiki.datadino.com/jgcwiki/index.php?title=Image:SuperPackME.zip
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (117 views)
2013-05-17 21:29:12

alaslipknot (124 views)
2013-05-16 21:24:48

gouessej (153 views)
2013-05-16 00:53:38

gouessej (146 views)
2013-05-16 00:17:58

theagentd (160 views)
2013-05-15 15:01:13

theagentd (145 views)
2013-05-15 15:00:54

StreetDoggy (189 views)
2013-05-14 15:56:26

kutucuk (213 views)
2013-05-12 17:10:36

kutucuk (212 views)
2013-05-12 15:36:09

UnluckyDevil (216 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.179 seconds with 22 queries.