EOS 2  1.1.0
Einfache Objektbasierte Sprache
TileSet.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.base;
2 
3 import java.awt.image.BufferedImage;
4 import java.io.IOException;
5 
6 import javax.imageio.ImageIO;
13 public class TileSet {
14  private BufferedImage image;
15  private int tileWidth;
16  private int tileHeight;
17  private int columns;
24  public TileSet(String source, int tileWidth, int tileHeight) {
25  try {
26  image = ImageIO.read(ResourceLoader.getResourceAsStream(source));
27  } catch (IOException fnfe) {
28  image = null;
29  return;
30  }
31 
32  this.tileWidth = tileWidth;
33  this.tileHeight = tileHeight;
34  this.columns = image.getWidth() / tileWidth;
35  }
44  public Image getTile(int nr) {
45  int row = nr / columns;
46  int column = nr % columns;
47  return new Image(image,tileWidth * column, tileHeight * row, tileWidth, tileHeight);
48  }
55  public Image getTile(int row, int column) {
56  return new Image(image,tileWidth * column, tileHeight * row, tileWidth, tileHeight);
57  }
58 }
static InputStream getResourceAsStream(String filename)
Image getTile(int row, int column)
Definition: TileSet.java:55
TileSet(String source, int tileWidth, int tileHeight)
Definition: TileSet.java:24
Impressum