Ejemplo n.º 1
0
void Sprite::Draw(Vector2 position, Color color, double scale, bool flipHorizontally)
{
    if (GetSpriteSheetImage() == NULL)
    {
        return;
    }

    Vector2 pixelSnappedPosition = Vector2((int)position.GetX(), (int)position.GetY());

    GetSpriteSheetImage()->Draw(
        pixelSnappedPosition,
        spriteClipRect,
        flipHorizontally,
        false /* flipVertically */,
        scale,
        color);
}
Ejemplo n.º 2
0
void Sprite::DrawClipped(Vector2 position, RectangleWH clipRect, bool flipHorizontally, Color color)
{
    if (GetSpriteSheetImage() == NULL)
    {
        return;
    }

    // Adjust the clip rect to account for the fact that we've eliminated blank space
    // that was around the source image.
    if (spriteDrawOffset.GetX() > 0 || spriteDrawOffset.GetY() > 0)
    {
        Vector2 oldClipRectPosition(clipRect.GetX(), clipRect.GetY());

        clipRect.SetX(clipRect.GetX() - spriteDrawOffset.GetX());
        clipRect.SetY(clipRect.GetY() - spriteDrawOffset.GetY());

        position += Vector2(clipRect.GetX(), clipRect.GetY()) - oldClipRectPosition;

        if (clipRect.GetX() + clipRect.GetWidth() > GetWidth())
        {
            clipRect.SetWidth(GetWidth() - clipRect.GetX());
        }

        if (clipRect.GetY() + clipRect.GetHeight() > GetHeight())
        {
            clipRect.SetHeight(GetHeight() - clipRect.GetY());
        }
    }

    Vector2 pixelSnappedPosition =
        Vector2(
            (int)(position.GetX() + (originalSize.GetX() > 0 && flipHorizontally ? originalSize.GetX() - GetWidth() - spriteDrawOffset.GetX() : spriteDrawOffset.GetX())),
            (int)(position.GetY() + spriteDrawOffset.GetY()));

    GetSpriteSheetImage()->Draw(
        pixelSnappedPosition,
        RectangleWH(
            spriteClipRect.GetX() + clipRect.GetX(),
            spriteClipRect.GetY() + clipRect.GetY(),
            clipRect.GetWidth(),
            clipRect.GetHeight()),
        flipHorizontally,
        false /* flipVertically */,
        1.0,
        color);
}
Ejemplo n.º 3
0
void Sprite::Draw(Vector2 position, Color color, double scale, bool flipHorizontally)
{
    if (GetSpriteSheetImage() == NULL)
    {
        return;
    }

    Vector2 pixelSnappedPosition =
        Vector2(
            (int)(position.GetX() + (originalSize.GetX() > 0 && flipHorizontally ? originalSize.GetX() - GetWidth() - spriteDrawOffset.GetX() : spriteDrawOffset.GetX())),
            (int)(position.GetY() + spriteDrawOffset.GetY()));

    GetSpriteSheetImage()->Draw(
        pixelSnappedPosition,
        spriteClipRect,
        flipHorizontally,
        false /* flipVertically */,
        scale,
        color);
}
Ejemplo n.º 4
0
void Sprite::DrawClipped(Vector2 position, RectangleWH clipRect, bool flipHorizontally, Color color)
{
    if (GetSpriteSheetImage() == NULL)
    {
        return;
    }

    Vector2 pixelSnappedPosition = Vector2((int)position.GetX(), (int)position.GetY());

    GetSpriteSheetImage()->Draw(
        pixelSnappedPosition,
        RectangleWH(
            spriteClipRect.GetX() + clipRect.GetX(),
            spriteClipRect.GetY() + clipRect.GetY(),
            clipRect.GetWidth(),
            clipRect.GetHeight()),
        flipHorizontally,
        false /* flipVertically */,
        1.0,
        color);
}