Add sprite drawing on actors
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,4 +29,8 @@ public interface SpritePixels
|
||||
int DEFAULT_SHADOW_COLOR = 3153952;
|
||||
|
||||
void drawAt(int x, int y);
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user