Add sprite drawing on actors

This commit is contained in:
Tyler Hardy
2017-10-19 12:03:18 -05:00
committed by Adam
parent f5df7af618
commit 97f7bd0c48
6 changed files with 80 additions and 0 deletions

View File

@@ -56,5 +56,7 @@ public interface Actor extends Renderable
Point getCanvasImageLocation(Graphics2D graphics, BufferedImage image, int zOffset);
Point getCanvasSpriteLocation(Graphics2D graphics, SpritePixels sprite, int zOffset);
Point getMinimapLocation();
}

View File

@@ -307,4 +307,32 @@ public class Perspective
return new Point(xOffset, yOffset);
}
/**
* Calculates sprite position and centers depending on sprite size.
*
* @param client
* @param graphics
* @param localLocation local location of the tile
* @param sprite SpritePixel for size measurement
* @param zOffset offset from ground plane
* @return a {@link Point} on screen corresponding to the given
* localLocation.
*/
public static Point getCanvasSpriteLocation(Client client, Graphics2D graphics, Point localLocation, SpritePixels sprite, int zOffset)
{
int plane = client.getPlane();
Point p = Perspective.worldToCanvas(client, localLocation.getX(), localLocation.getY(), plane, zOffset);
if (p == null)
{
return null;
}
int xOffset = p.getX() - sprite.getWidth() / 2;
int yOffset = p.getY() - sprite.getHeight() / 2;
return new Point(xOffset, yOffset);
}
}

View File

@@ -29,4 +29,8 @@ public interface SpritePixels
int DEFAULT_SHADOW_COLOR = 3153952;
void drawAt(int x, int y);
int getWidth();
int getHeight();
}