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

JGO Coder


Projects: 6


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: 10
Projects: 4


David Aaron Muhar


« Reply #1 - Posted 2009-01-01 18: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 Ninja


Medals: 15
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.

 

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

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (10 views)
2014-12-27 04:03:04

TheDudeFromCI (13 views)
2014-12-27 02:14:49

Mr.CodeIt (25 views)
2014-12-23 03:34:11

rwatson462 (56 views)
2014-12-15 09:26:44

Mr.CodeIt (46 views)
2014-12-14 19:50:38

BurntPizza (92 views)
2014-12-09 22:41:13

BurntPizza (113 views)
2014-12-08 04:46:31

JscottyBieshaar (84 views)
2014-12-05 12:39:02

SHC (94 views)
2014-12-03 16:27:13

CopyableCougar4 (102 views)
2014-11-29 21:32:03
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!