Larger than normal Tiles?

I am making a small Tile based game and I found a possible problem. Each of my Tiles are 64x64 and I’m wondering if its possible to have a single tile larger than it should be? It seems like an rather inefficient method to place each tile individualy. As I plan on having many buildings that would take several hundred tiles which would take hundreds of Classes.

Sorry If this sounds very noobie as although I have used Java for quite a while I have only just started creating JFrames recently

Hi!

Are you using a library? or are you writing from scratch?
Also, why are you creating separate classes for a building?
If you create a building isn’t it better to reuse it?


ArrayList<Building> buildings = new ArrayList<Building>();
buildings.add(new Building(sprite, xPos, yPos, width, height)); // could be combined with a 'for' loop

// Rendering
for (int i = 0; i < buildings.size(); i++) {
  Building building = buildings.get(i);
  building.render(screen);
}

Something like that could be more useful.
And if you want bigger tiles, that wouldn’t be possible. One thing what you could do is splitting your image into parts of 64x64 and render those.

What kind of game are you making?
If you consider using a library take a look at:
LibZ | LibZ Github | LibZ Download | LibZ Documentation

The way I learned to create tiles was by creating a class for each one. Also I would prefer not to have duplicate buildings everywhere, but yes I would be reusing some. My game is a very simple 2d game in which the player simply walks around. I decided to start basing it off a game I was very familiar with - Pokemon.

To be honest I learned how to create tiles from a Youtube video (I know its a very bad way to learn, but it was the only I could find) and I get the location to render a tile from a .txt file.

From the way your code looks like mine is a pretty terrible way of doing so.

Here is my code: https://github.com/TheGamerPlayz/Pokemon/tree/master/src/me/xthegamerplayz/FirstGame

Here is the series in which I learned how to create what I have: https://www.youtube.com/playlist?list=PLah6faXAgguMnTBs3JnEJY0shAc18XYQZ

Do you mean class or object? You most definitely do not want to create a class for each tile, you’d want fields that can accommodate the differences between the tiles so you end up with one class, but can create different objects utilizing the class.

From there if it gets too complex you can use inheritance to create subtypes, for instance a door tile could extend the tile class which adds a trigger so that when it’s entered you load a new area. You don’t need the trigger functionality in a normal tile, so you might not want it mixed in with everything else, but you also might not care so you can keep it in the tile class.

why all so difficult? :slight_smile:

a tilemap is nothing but a simple array of mapwidth*mapheight filled with numbers (integers) that translate to texture/sprite images

if the value of a tile is 0 there is no tile, and you can then give every other number the value of the tile to use.

in that case you could just have this square:

1 | 0
0 | 0

where tile 1 is actually the size of 4 tiles and would overlap over the 0’s and so you can have bigger tiles amongst the small tiles.

I see what you mean, but I am not at all familiar enough to change the way my entire game renders without a guide.

For buildings I wanted to avoid the same thing you’re facing, splitting it up into many tiles.

I made a separate tile type that is just a bigger size. for example



public class Tile {
	
	public static final int NORMAL_TILE = 2;
	public static final int SUPER_TILE = 3;

	public int x, y, sizeX, sizeY;

	public Tile(int ex, int why, int type) {
		
		x = ex;
		y = why;
		
		if (type == NORMAL_TILE) {
			sizeX = 64;
			sizeY = 64;
		} else if (type == SUPER_TILE) {
			sizeX = 128;
			sizeY = 128;
		}

	}


	
}

// pending on render method it would look something like this 
// though this method is likely in another class file
g.drawImage(tileImage, tile.x, tile.y, tile.sizeX, tile.sizeY, null);

What are you using to make the game?
How is it being rendered?