class Map {
Layer[] layers;
}
class Layer {
Tile[] tiles;
}
class Tile {
int x, y, id;
}
Note that ( depending on your grid size and tile density or how you want to retrieve the information ) you could rid of x and y, and instead use Tile[][] tiles
Note also: there are many many different ways to do this! Your question does not have enough detail.
How to adding a tile in map and layer as GameObject ?
ArrayList<Map> maps = new ArrayList<Map>();
ArrayList<GameObject> objects = new ArrayList <GameObject>();
void setup() {
size(400, 200);
// # ADD MAP # \\
maps.add( new Map());
// # ADD LAYER # \\
maps.get(0).layers.add( new Layer());
// # ADD SOME TILES # \\
maps.get(0).layers.get(0).tiles.add( new Tile(0, 50));
maps.get(0).layers.get(0).tiles.add( new Tile(0, 150));
maps.get(0).layers.get(0).tiles.add( new Tile(100, 0));
}
void draw() {
for (GameObject entity : objects) {
entity.draw(); // ### I WANT TO DRAW ALL OF OBJECTS, BUT NOW I HAVE ONLY TILES... BUT NOT WORKING ###
}
/*for (int i = 0; i < maps.size(); i++) {
maps.get(i).draw(); ### OLD CODE ###
}*/
}
class Map {
ArrayList<Layer> layers = new ArrayList<Layer>();
void draw() {
for (int i = 0; i < layers.size(); i++) {
layers.get(i).draw();
}
}
}
class Layer {
ArrayList<Tile> tiles = new ArrayList<Tile>();
void draw() {
for (int i = 0; i < tiles.size(); i++) {
tiles.get(i).draw();
}
}
}
class Tile extends GameObject{
Tile(int x, int y) {
this.x = x;
this.y = y;
}
void draw() {
rect(x, y, 50, 50);
}
}
abstract class GameObject {
int x, y;
abstract void draw();
}
I wrote a Map for you sometime ago. Didn't you like it?
Maybe you start by explaining in a long way, what you want to achieve with layers, what the relationship is between map, layer and field, if the map is bigger than screen or not and what you have problems with exactly.
What are your goals.
How to adding a tile in map and layer as GameObject ?
When you ask questions like this, nobody knows what you want. It's not even clear what you mean, which is part of what? Do you see that I wrote more now then you in the entire discussion (or forum)?
Answers
Note that ( depending on your grid size and tile density or how you want to retrieve the information ) you could rid of x and y, and instead use
Tile[][] tiles
Note also: there are many many different ways to do this! Your question does not have enough detail.
nice, so and how to create or get x y ?
good ?
or this ???? can i make tile as extends object ?
How to adding a tile in map and layer as GameObject ?
Can you help me ? :/
I wrote a Map for you sometime ago. Didn't you like it?
Maybe you start by explaining in a long way, what you want to achieve with layers, what the relationship is between map, layer and field, if the map is bigger than screen or not and what you have problems with exactly. What are your goals.
When you ask questions like this, nobody knows what you want. It's not even clear what you mean, which is part of what? Do you see that I wrote more now then you in the entire discussion (or forum)?
As Jeremy has said:
I want to add tile and draw with object array....
And how to get not public variable ?
There are many many different ways to do this! Your question does not have enough detail.
Different data structures and algorithms make sense for tiling:
"How do I do it?"
DO WHAT??
Your question does not have enough detail.
the size error above occurred because in objects there are tiles and effects mixed but only effects have size, tiles haven't (or whatever reason)
corrected version: