Game Development Reference
In-Depth Information
Vector2f wantedLocation = newLocation.add(new
Vector2f(x,y));
if(!cachedTiles.containsKey(wantedLocation)){
Geometry g = new Geometry(wantedLocation.x + ", " +
wantedLocation.y, new Box(tileSize * 0.5f, 1,
tileSize * 0.5f));
12. We set location to be the delta distance from newLocation . If currentTile
is not null, we add its localTranslation too:
Vector3f location = new Vector3f(x * tileSize, 0, y *
tileSize);
if(currentTile != null){
location.addLocal(currentTile.getLocalTranslation());
}
g.setLocalTranslation(location);
13. Finally, attach g to the control's spatial and put g in the cachedTiles map
with wantedLocation as the key.
14. Now, for the deleteTiles method, it also takes a Vector2f parameter
called newLocation as the input.
15. Like the updateTiles method, iterate through the cachedTiles map. Look
for those tiles that are now more than two tiles away in either direction and add
their location to a list called tilesToDelete :
Iterator<Vector2f> it =
cachedTiles.keySet().iterator();
List<Vector2f> tilesToDelete = new
ArrayList<Vector2f>();
while(it.hasNext()){
Vector2f tileLocation = it.next();
if(tileLocation.x>newLocation.x + 2 ||
tileLocation.x<newLocation.x - 2 ||
tileLocation.y>newLocation.y + 2 ||
tileLocation.y<newLocation.y - 2){
tilesToDelete.add(tileLocation);
}
}
Search WWH ::




Custom Search