Skip to main content
added 20 characters in body
Source Link
Madmenyo
  • 2k
  • 15
  • 28

Here is a basic example of how a tilemapTile class looks like.

public class Tile { boolean walkable; //here I make use of "your way" to lookup the texture of this tile. int textureId; }

public class Tile {
    boolean walkable;
    //here I make use of "your way" to lookup the texture of this tile.
    int textureId;
}

when I want to create the map, I populate and draw this you can dothe array:

Here is a basic example of how a tilemap looks like.

public class Tile { boolean walkable; //here I make use of "your way" to lookup the texture of this tile. int textureId; }

when I want to create, populate and draw this you can do:

Here is a basic example of how a Tile class looks like.

public class Tile {
    boolean walkable;
    //here I make use of "your way" to lookup the texture of this tile.
    int textureId;
}

when I want to create the map, I populate and draw the array:

added 1515 characters in body
Source Link
Madmenyo
  • 2k
  • 15
  • 28

-Edit-

Here is a basic example of how a tilemap looks like.

public class Tile { boolean walkable; //here I make use of "your way" to lookup the texture of this tile. int textureId; }

when I want to create, populate and draw this you can do:

Tile[][] tileMap = new Tile[width][height];
        for (int y = 0; y < width; y++)
        {
            for (int x = 0; x <= height; x++)
            {                
                spriteBatch.draw(textureDictionary.get(tileMap[x][y].textureId), position, etc);                
            }
        }

Now this is not much different then your method, only mine stores if the tile can be walked upon too. Your walls should probably never be walked upon and floors should so why bother changing to my method?

Scalability is the answer. What if you decide that you want to add objects to your map? If you have say 10 objects like tables, chairs, pillars, etc then for each int that represents a floor you need 10 more of those. Where I just add another int for the objects texture or perhaps the object itself if it has more properties like a tile.

Yes you could add another array to represent your objects and draw that over your tiles. But then you decide that object a can damage the player in a certain state. Now you need to make another array or a extra int to refer too. Where I change the behavior of a object in it's class. This is why you use a object oriented language anyway.

-Edit-

Here is a basic example of how a tilemap looks like.

public class Tile { boolean walkable; //here I make use of "your way" to lookup the texture of this tile. int textureId; }

when I want to create, populate and draw this you can do:

Tile[][] tileMap = new Tile[width][height];
        for (int y = 0; y < width; y++)
        {
            for (int x = 0; x <= height; x++)
            {                
                spriteBatch.draw(textureDictionary.get(tileMap[x][y].textureId), position, etc);                
            }
        }

Now this is not much different then your method, only mine stores if the tile can be walked upon too. Your walls should probably never be walked upon and floors should so why bother changing to my method?

Scalability is the answer. What if you decide that you want to add objects to your map? If you have say 10 objects like tables, chairs, pillars, etc then for each int that represents a floor you need 10 more of those. Where I just add another int for the objects texture or perhaps the object itself if it has more properties like a tile.

Yes you could add another array to represent your objects and draw that over your tiles. But then you decide that object a can damage the player in a certain state. Now you need to make another array or a extra int to refer too. Where I change the behavior of a object in it's class. This is why you use a object oriented language anyway.

added 137 characters in body
Source Link
Madmenyo
  • 2k
  • 15
  • 28

The only thing you need is to hookup tileWidth and tileHeight to your variables. You might want to change the variables to private with get/set, but since they are only coordinates I like to have quick access to them.

The only thing you need is to hookup tileWidth and tileHeight to your variables.

The only thing you need is to hookup tileWidth and tileHeight to your variables. You might want to change the variables to private with get/set, but since they are only coordinates I like to have quick access to them.

Source Link
Madmenyo
  • 2k
  • 15
  • 28
Loading