Hi, this is my first post. I really hope you can help me.
Im making a isometric game, with a cartesian map. the map is loaded from an image file into an array. The screen class stands for the renderen and gets the pixels from a pixel array saved in a Sprite, and put that pixel value into the Screens pixel array, and the screens draws its own array onto the screen.
Screens renderTile method gets the isometric coordinates, and draws them onto the screen.
public void renderTile(int xp, int yp, Tile tile) {
xp -= _xOffset;
yp -= _yOffset;
int color;
for (int y = 0; y < tile.getSprite().getHeight(); y++) {
int ya = y + yp;
for (int x = 0; x < tile.getSprite().getWidth(); x++) {
int xa = x + xp;
if (xa < -tile.getSprite().getWidth() || xa >= _width || ya < 0
|| ya >= _height) {
break;
}
if (xa < 0) {
xa = 0;
}
color = tile.getSprite().getPixels()[x + y
* tile.getSprite().getWidth()];
if (color != 0xffff00ff) {
_pixels[xa + ya * _width] = color;
}
}
}
}
Tiles render method takes the cartesian coordinates and convert them into isometric coordinates, and sends them into Screen, where they are draw as in the method above:
public void isometricRender(int x, int y, Screen screen) {
int isoX = (x - y) / 2;
int isoY = (x - y) / 2;
screen.renderTile(isoX * WIDTH, isoY * HEIGHT, this);
}
I really appriciate your help