Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (684)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (752)
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 2307 times)
0 Members and 1 Guest are viewing this topic.
Offline luisoft

JGO Coder


Projects: 6
Exp: 10 years


Java games rock!


« Posted 2009-01-01 17: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: 12
Projects: 4


David A M


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

if the sprites are small why not use .gif?
Offline moogie

JGO Ninja


Medals: 16
Projects: 6
Exp: 10 years


Java games rock!


« Reply #2 - Posted 2009-01-02 04: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

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

 
orrenravid (238 views)
2016-07-16 03:57:23

theagentd (308 views)
2016-07-11 14:28:54

Hydroque (394 views)
2016-07-06 05:56:57

Hydroque (550 views)
2016-07-03 08:52:54

GrandCastle (415 views)
2016-07-01 09:13:47

GrandCastle (408 views)
2016-07-01 09:09:45

CopyableCougar4 (462 views)
2016-06-25 16:56:52

Hydroque (430 views)
2016-06-22 02:17:53

SwampChicken (395 views)
2016-06-20 13:22:57

SwampChicken (308 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17
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!