[quote]sure, but how do the two methods interact… i.e. does calling setOfffsets mean that the later render call has these offsets applied to isoX and isoY? if so then you are doubly taking scrolling into account. The isoX and isoY values already have scrolling taken into account and should be used directly when rendering.
[/quote]
Levels isometricRender method:
public void isometricRender(int xScroll, int yScroll, Screen screen) {
screen.setOffsets(xScroll, yScroll);
int VIEW_PORT_HEIGHT = 5; // in cartesian map scale
// minus one. assuming square map.
int VIEW_PORT_WIDTH = 5; // in cartesian map scale
float scrollYScreenUnit = 0; // should be updated when scrolling the
// view port. the unit is in cartesian
// map scale. i.e. 1 unit = 1 tile
float scrollXScreenUnit = 0; // should be updated when scrolling the
// view port. the unit is in cartesian
// map scale.
// determine whether to start on an "alternative" line. i.e. offset x by
// half the tile width
int alternateScanline = (int) ((scrollYScreenUnit % 1) * 2);
// determine the cartesian co ordinate of the top left corner of the
// current view.
int scrollMapX = (int) ((scrollYScreenUnit + 0.5F) + 0.5F * (scrollXScreenUnit));
// determine the cartesian co ordinate of the top left corner of the
// current view.
int scrollMapY = (int) ((scrollYScreenUnit + 0.5F) - 0.5F * (scrollXScreenUnit));
for (int y = -1; y < VIEW_PORT_HEIGHT * 2; y++) {
alternateScanline = (++alternateScanline) % 2;
// cartesian co-ordniate of current tile to be rendered
int xGame = scrollMapX;
// cartesian co-ordniate of current tile to be rendered
int yGame = scrollMapY;
for (int x = -2; x < VIEW_PORT_WIDTH; x++) {
// convert to isometric X
int isoX = (int) ((xGame - yGame - scrollXScreenUnit - 1.0F)
* Tile.WIDTH / 2);
// convert to isometric Y
int isoY = (int) ((0.5F * (xGame + yGame) - scrollYScreenUnit - 0.25F)
* Tile.HEIGHT / 2);
if (xGame > 0 && yGame > 0 && xGame < _width - 1
&& yGame < _height - 1) {
getTile(x, y).render(isoX, isoY, screen);
}
xGame++;
yGame--;
}
// update the statring point of the next line of tiles based on
// whether it is an alternative line
scrollMapY += alternateScanline;
// or not. if it is then the line is shifted out of phase by half.
scrollMapX += 1 - alternateScanline;
}
for (int i = 0; i < _entities.size(); i++) {
_entities.get(i).isometricRender(screen);
}
for (int i = 0; i < _players.size(); i++) {
// _players.get(i).isometricRender(screen);
}
for (int i = 0; i < _projectiles.size(); i++) {
_projectiles.get(i).isometricRender(screen);
}
for (int i = 0; i < _particles.size(); i++) {
_particles.get(i).isometricRender(screen);
}
}
Render method in Tile:
public void render(int x, int y, Screen screen) {
screen.renderTile(x * WIDTH, y * HEIGHT, this);
}
Screens renderTile method:
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;
}
}
}
}
The render method for player:
public void isometricRender(Screen screen) {
int isoX = (int) Math.round(_x - _y);
int isoY = (int) Math.round((_x + _y));
screen.renderNPC(isoX - (SIZE / 2), isoY - (SIZE / 2), _sprite, 0);
}