473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Make this packer to work?

im in the creation of an sprite packer for a game, but i can't get it to run?
a friend sent me the source for it, so i have no idea what to do from this?
so far:
Expand|Select|Wrap|Line Numbers
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.io.FileOutputStream;
  4. import java.io.BufferedInputStream;
  5. import java.nio.ByteBuffer;
  6. import java.awt.Toolkit;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.image.BufferedImage;
  10. import javax.swing.ImageIcon;
  11. import javax.imageio.ImageIO;
  12. import java.util.TreeMap;
  13. import java.util.Map.Entry;
  14. import java.util.Enumeration;
  15. import java.util.zip.ZipFile;
  16. import java.util.zip.ZipEntry;
  17. import java.util.zip.ZipOutputStream;
  18.  
  19. public class SpriteEditor {
  20.     public static final String IMG_DIR = "./img/";
  21.  
  22.     public static final void main(String[] args) {
  23.         SpriteEditor editor = new SpriteEditor(new File("./sprites.Tx"));
  24.     }
  25.  
  26.     public SpriteEditor(File file) {
  27.         TreeMap<Integer, Sprite> sprites = readZip(file);
  28.  
  29.         sprites.put(2382, createSprite(new File("./new/1370.png"), true, 6, 2, 41, 29));
  30.         System.out.println("Successfully packed new sprites!");
  31.  
  32.         writeZip(sprites, file);
  33.     }
  34.  
  35.     public Sprite createSprite(File file, boolean requiresShift, int xShift, int yShift, int something1, int something2) {
  36.         try {
  37.             Sprite sprite = Sprite.fromImage(loadImage(file));
  38.  
  39.             sprite.setRequiresShift(requiresShift);
  40.             sprite.setShift(xShift, yShift);
  41.             sprite.setSomething(something1, something2);
  42.  
  43.             return sprite;
  44.         }
  45.         catch(Exception ioe) {
  46.             System.out.println(ioe);
  47.             return null;
  48.         }
  49.     }
  50.  
  51.     public TreeMap<Integer, Sprite> readZip(File file) {
  52.         try {
  53.             TreeMap<Integer, Sprite> sprites = new TreeMap<Integer, Sprite>();
  54.  
  55.             ZipFile zip = new ZipFile(file);
  56.             for(Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>)zip.entries();entries.hasMoreElements();) {
  57.                 ZipEntry entry = entries.nextElement();
  58.                 BufferedInputStream in = new BufferedInputStream(zip.getInputStream(entry));
  59.                 ByteBuffer buffer = streamToBuffer(in);
  60.                 in.close();
  61.  
  62.                 Sprite sprite = Sprite.unpack(buffer);
  63.                 sprites.put(Integer.parseInt(entry.getName()), sprite);
  64.             }
  65.             return sprites;
  66.         }
  67.         catch(IOException ioe) {
  68.             System.err.println(ioe);
  69.             return null;
  70.         }
  71.     }
  72.  
  73.     public boolean writeZip(TreeMap<Integer, Sprite> sprites, File file) {
  74.         try {
  75.             ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
  76.             out.setLevel(9);
  77.  
  78.             for(Entry<Integer, Sprite> e : sprites.entrySet()) {
  79.                 String name = String.valueOf(e.getKey());
  80.                 Sprite sprite = e.getValue();
  81.  
  82.                 out.putNextEntry(new ZipEntry(name));
  83.                 out.write(sprite.pack().array());
  84.                 out.closeEntry();
  85.             }
  86.             out.close();
  87.             return true;
  88.         }
  89.         catch(IOException ioe) {
  90.             System.err.println(ioe);
  91.             return false;
  92.         }
  93.     }
  94.  
  95.     public static final ByteBuffer streamToBuffer(BufferedInputStream in) throws IOException {
  96.         byte[] buffer = new byte[in.available()];
  97.         in.read(buffer, 0, buffer.length);
  98.         return ByteBuffer.wrap(buffer);
  99.     }
  100.  
  101.     public static BufferedImage loadImage(File file) throws IOException {
  102.         Image image = new ImageIcon(Toolkit.getDefaultToolkit().getImage(file.getAbsolutePath())).getImage();
  103.         BufferedImage buffImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
  104.  
  105.         Graphics g = buffImage.createGraphics();
  106.         g.drawImage(image, 0, 0, null);
  107.         g.dispose();
  108.  
  109.         return buffImage;
  110.     }
  111.  
  112. }
and:
Expand|Select|Wrap|Line Numbers
  1. sprites.put(1370, createSprite(new File("./new/1370.png"), true, 6, 2, 41, 29));
any help is appriciated.

Sincerly.
Jul 31 '08 #1
3 1534
r035198x
13,262 8TB
What did he say you should do with it?
What did you try to do with it and what error did it give?
Jul 31 '08 #2
thats the thing, he just gave me the packer source (wich will pack the sprites)

and:
"Ok you will need to make a file with this named Sprites.Tx"
Expand|Select|Wrap|Line Numbers
  1. sprites.put(1370, createSprite(new File("./new/1370.png"), true, 6, 2, 41, 29));
"Basicly this is what makes ur png into rsc format for sprites
6, 2, 41, 29
6 > xshift
2 > yshift
41 > something1
29 > somtthing2"

and, from here im stuck, i guess it needs an .bat to run it with like;
java -classpath spriteeditor.java
pause

but this gives me options that has nothing to do with the packer method.
Jul 31 '08 #3
r035198x
13,262 8TB
What you have is source code which needs to be compiled into a class file
Best thing to do is to get your friend and ask him for instructions on how to use that source code. e.g the tool for compiling the source file is javac not java.
Jul 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: WindAndWaves | last post by:
Hi Gurus I am keen to make a search page on a website, but I have absolutely zero experience with PHP. I am going to hire an expert, but I thought that it may pay to try it a bit first myself...
0
by: pptran | last post by:
Hi, I am pretty new to building and installing Perl. Can someone help explain the severity of the following Perl 5.8.4 build error message? ==================================================...
19
by: Swaregirl | last post by:
Hello, I would like to build a website using ASP.NET. I would like website visitors to be able to download code that I would like to make available to them and that would be residing on my...
14
by: kpp9c | last post by:
I would like to use the power of Python to build some list structures for me. Namely i have organized a bunch of folders that have soundfiles in them and would like Python to slurp up all the...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
17
by: stubbsie | last post by:
Hi, I have redesigned our official public government website in .net and it has taken me a few months to redo. I have been the sole designer of the website from its humble beginnning a few years...
7
by: Hal Vaughan | last post by:
I have a problem with port forwarding and I have been working on it for over 2 weeks with no luck. I have found C programs that almost work and Java programs that almost work, but nothing that...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.