Note that there are some explanatory texts on larger screens.

plurals
  1. POWhats a good way to save tile sprites from my level editor?
    text
    copied!<p>I have built a tile based level editor in java, It is just about completed, but as I was writing the method to save the level, that all of my tiles were image sprites and I dont know of a way to save them so that the actual game can read them without making each tile it's own image file which I would then need to import to read in the real game. (there are over 700 possible tiles, a level would probably use 100 of those);</p> <p>My question to you all: what is the best way to save all these tiles? I am familiar with saving things to a text file but I am not able to save these images in the same way. Is there a way to save the level so that my text based information is saved in the same place as my tile sprites?</p> <p>here is my tile class and what I have so far in terms of my save method</p> <pre><code> public class Tile { int x, y, w, h, type; BufferedImage layer1Image; BufferedImage layer2Image; BufferedImage layer3Image; BufferedImage layer4Image; boolean walkable; public Tile(int x, int y, int w, int h) { walkable = false; this.x = x; this.y = y; this.w = w; this.h = h; type = 0; layer1Image = null; layer2Image = null; layer3Image = null; layer4Image = null; } public Tile() { } public int getX() { return x; } public int getY() { return y; } public int getW() { return w; } public int getH() { return h; } public void setX(int newX) { x = newX; } public void setY(int newY) { y = newY; } public void setW(int newW) { w = newW; } public void setH(int newH) { h = newH; } public boolean mouseOver(int mouseX, int mouseY) { if (mouseX &gt; x &amp;&amp; mouseX &lt; x + w &amp;&amp; mouseY &gt; y &amp;&amp; mouseY &lt; y + h) { return true; } return false; } public int getType() { return type; } public boolean getWalkable() { return walkable; } public BufferedImage getLayer1Image() { return layer1Image; } public BufferedImage getLayer2Image() { return layer2Image; } public BufferedImage getLayer3Image() { return layer3Image; } public BufferedImage getLayer4Image() { return layer4Image; } public void clearImages() { layer1Image = null; layer2Image = null; layer3Image = null; layer4Image = null; walkable = true; } public void setImage(BufferedImage image, int layer) { switch (layer) { case 0: layer1Image = image; break; case 1: layer2Image = image; break; case 2: layer3Image = image; case 3: layer4Image = image; } } public void display(Graphics g, int x, int y, int w, int h, int zoom) { g.setColor(Color.BLACK); g.drawImage(layer1Image, x, y, w, h, null); g.drawImage(layer2Image, x, y, w, h, null); g.drawImage(layer3Image, x, y, w, h, null); g.drawImage(layer4Image, x, y, w, h, null); g.drawRect(x, y, w, h); } public void getAttributes(Tile tile) { layer1Image = tile.getLayer1Image(); layer2Image = tile.getLayer2Image(); layer3Image = tile.getLayer3Image(); layer4Image = tile.getLayer4Image(); x = tile.getX(); y = tile.getY(); w = tile.getW(); h = tile.getH(); walkable = tile.getWalkable(); type = tile.getType(); } public void setWalkable(boolean b) { walkable = b; } // Here is the save, its in a different class in case my formatting in the post is screwy public void doSaveAsText() { if (fileDialog == null) { fileDialog = new JFileChooser(); } File selectedFile; if (editFile == null) { selectedFile = new File("levelData.txt"); } else { selectedFile = new File(editFile.getName()); } fileDialog.setSelectedFile(selectedFile); fileDialog.setDialogTitle("Select File to be Saved"); int option = fileDialog.showSaveDialog(this); if (option != JFileChooser.APPROVE_OPTION) { return; } selectedFile = fileDialog.getSelectedFile(); if (selectedFile.exists()) { int response = JOptionPane.showConfirmDialog(this, "Already exists, overwrite?", "Confirm Save", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } PrintWriter out; try{ FileWriter stream = new FileWriter(selectedFile); out = new PrintWriter(stream); } catch (Exception e){ JOptionPane.showMessageDialog(this, "error"); return; } try{ out.println("LevelEditor v1.0"); for(int i = 0; i &lt; mapPanel.tilesList.size(); i++){ Tile currentTile = mapPanel.tilesList.get(i); out.println("startTile"); out.println("" + currentTile.getX()); out.println("" + currentTile.getY()); out.println("" + currentTile.getW()); out.println("" + currentTile.getH()); out.println("" + currentTile.getWalkable()); out.println("endTile"); } out.close(); }catch(Exception e){ System.exit(0); } } Any suggestions would be great </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload