Witam,
Zacząłem robić grę RPG, idzie całkiem niezle, ale...
Próbuje zrobić tak by moja postać chodziła całymi kratkami (grid system). Przykład takiego chodzenia można znalezć np. w grze Tibia czy Pokemony.
Problem leży w tym, że moja postać zamiast się poruszać pixelami (pokonywać drogę), można powiedzieć, że się teleportuje, co zle wygląda i nie tego chcę.
Tak wygląda mój system chodzenia aktualnie, ale nie mam pojęcia jak sprawić by postać zamiast się teleportować pokonywała tą drogę. (Próbowałem różne timery, sleep czy pętle for, ale nie działało, albo nie umiałem tego zrobić)
public void moveX() throws InterruptedException{
if(xMove > 0){ // MOVING RIGHT
int tx = (int) (x + xMove + bounds.x + bounds.width) / Tile.TILEWIDTH;
//Checks for collisions
if(!collisionWithTile(tx, (int) (y + bounds.y) / Tile.TILEHEIGHT )
&& !collisionWithTile(tx, (int) (y + bounds.y + bounds.height) / Tile.TILEHEIGHT )){
//tileSize = 64
x += tileSize;
}else{
x = tx * Tile.TILEWIDTH - bounds.x - bounds.width -1;
}
}else if(xMove < 0){ //MOVING LEFT
int tx = (int) (x + xMove + bounds.x) / Tile.TILEWIDTH;
if(!collisionWithTile(tx, (int) (y + bounds.y) / Tile.TILEHEIGHT)
&& !collisionWithTile(tx, (int) (y + bounds.y + bounds.height) / Tile.TILEHEIGHT)){
x -= tileSize;
}else{
x = tx * Tile.TILEWIDTH + Tile.TILEWIDTH - bounds.x ;
}
}
}