Jump to content
  • Advertisement
Sign in to follow this  

Java Tileset Help!

This topic is 2545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay so, I'm kind lost here. Java has a really funky way of displaying graphics, and I've hit a wall trying to get this code to work so, here's the source:

//Frame Class handles the window

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JFrame;

public class Frame extends JFrame {

public Frame() {
setTitle("Tile Test");
setSize(600, 400);

public static void main(String[] args) {
new Frame();
public void paint(Graphics g) {
public void paintComponent(Graphics g) {

// ^^^ Pretty fundamental stuff


//Tile Class should do all the work.

import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;

public class Tile {
int mapArray[][] = {{1, 2, 3},{3, 2, 1}, //this array is the "map" I am using. Each value in the array translates to the t1, t2, t3,
{2, 1, 3},{3, 1, 2}}; //images below

public int mapHeight = 4; //Number of tiles per map (keeping it small for now)
public int mapWidth = 4; // "
public final int tileWidth = 32; //Tile dimensions
public final int tileHeight = 32; // "
public int x; //x location of tile on screen
public int y; //"
int tileType = 0; //Which tile is it?
Image img;
ImageIcon t0 = new ImageIcon("C:\\test\\tile1.png"); //Tile graphics 1
ImageIcon t1 = new ImageIcon("C:\\test\\tile2.png"); //etc
ImageIcon t2 = new ImageIcon("C:\\test\\tile3.png");

public static void display(int x[][]) {
for(int row = 0; row < x.length; row++) {//loops through rows
for(int column = 0; column < x[row].length; column++) {

So I have the images configured-ish, I have the basic "loop through array and figure out what each tile is", but I dunno how to finish this... no tiling tutorials in Java online, I spent a long time looking. Tried to look at ones from other languages, all I could find was C# and XNA (and it was a really complex and functional tileset, very hard to follow he had error checking and such in it), and SDL (on Lazyfoo's SDL site), which I couldn't translate from SDL to Java.

So basically, I need to get the for statements to read the values at the index in the array, I figured I'd use some nested if statements, maybe a switch. Once that works I need to send the result of the for's to paintComponent in the frame class, to paint it on the screen.

Hoping for a miracle. Really appreciate your help. I've made a ton of games like platformers, and asteroids, but none of them directly get into tilesets.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!