Claro que isso eh java basico, que tolice ficar pedindo para mudar.
O que pode ser basico para mim, pode ser avancado para alguem e vice versa.
No máximo este post poderia ser colocado em Interface Grafica, mas não
em Java Avançado.
E ficar duplicando post só para ficar na separação certa é bobagem.
Mas a questao é ajudar aquele que iniciou o post, então gostaria de saber
você quer uma solução por imagens ou uma solução grafica, por desenho?
Também não consigo ver, no momento, o youtube. Entao nao sei bem o que vc quer
Eu acho que uma boa solução para fazer isso seria usando Sprites, fica bem rapido:
abaixo um codigo de exemplo:
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
/**
* @author Administrator
*
* TODO Explain me
*/
public class TileTest extends JFrame {
int screenWidth, screenHeight;
final int TILE_WIDTH = 32;
final int TILE_HEIGHT = TILE_WIDTH;
int tilePosX;
int tilePosY;
final int TILE_COLUMN_CNT = 3;
final int TILE_ROW_CNT = 4;
VolatileImage[] tiles;
BufferStrategy strategy;
private Thread renderer = new Thread() {
public void run() {
int i = 0;
while (true) {
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.clipRect(0, 0, screenWidth, screenHeight);
g.drawImage(tiles[i], tilePosX, tilePosY, TileTest.this);
i = ++i % tiles.length;
g.dispose();
strategy.show();
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
public TileTest() {
super("TileTest");
setDefaultCloseOperation(EXIT_ON_CLOSE);
screenWidth = 320;
screenHeight = 240;
tilePosX = (screenWidth - TILE_WIDTH) / 2;
tilePosY = (screenHeight - TILE_HEIGHT) / 2;
setSize(screenWidth, screenHeight);
setResizable(false);
setVisible(true);
initGFX();
createBufferStrategy(2);
strategy = getBufferStrategy();
}
/**
*
*/
private void initGFX() {
try {
BufferedImage tilesMap = ImageIO
.read(new File("c:/sprite.PNG"));
int width = tilesMap.getWidth();
int height = tilesMap.getHeight();
tiles = new VolatileImage[TILE_ROW_CNT * TILE_COLUMN_CNT];
for (int i = 0, y = 0; i < TILE_ROW_CNT; i++) {
for (int j = 0, x = 0; j < TILE_COLUMN_CNT; j++) {
VolatileImage vImg = this.createVolatileImage(TILE_WIDTH,
TILE_HEIGHT);
vImg.getGraphics()
.drawImage(
tilesMap.getSubimage(x, y, TILE_WIDTH,
TILE_HEIGHT), 0, 0, this);
tiles[i * TILE_COLUMN_CNT + j] = vImg;
x += TILE_WIDTH;
}
y += TILE_HEIGHT;
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new TileTest().start();
}
private void start() {
renderer.start();
}
}