Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Flip, Rotate Sprite Separately?

$
0
0

@Shadowblitz16 wrote:

hello I have recently picked up monogame again and so far I like it.
however while writing my drawTile function I wanted to allow the user to pass in the following

  • rotation (degrees) {0=up, 1=left, 2=down,3=right}
  • flipx (bool) {false=nomirror, 1=mirroredx}
  • flipy (bool) {false=nomirror, 1=mirroredy}

the problem is when I looked up spriteBatch.Draw() method it looks as if its rotated and not mirrored when fliped.

my code is currently this..

    static class Graphics
    {
        static GraphicsDeviceManager graphics;
        static void DrawTile(int tile, int x, int y, int w=1, int h=1)
    {
        int sx = (int)Math.Floor((decimal)tile % Globals.TILEBANK_W);
        int sy = (int)Math.Floor((decimal)tile / Globals.TILEBANK_W);
        int ex = sx + w;
        int ey = sy + h;

        for (int oy=sy; oy<ey; oy++)
        for (int ox=sx; ox<ex; ox++)
        {
            int oi    = ox + oy * Globals.TILEBANK_W;
            int index = (int)Math.Floor((decimal)(oi / (Globals.TILEBANK_W * Globals.TILEBANK_H)));
        
            Texture2D tileBank = TileBank.Get(index);
            Rectangle tileRect = new Rectangle
            (
                (int)Math.Floor((decimal)(oi % Globals.TILEBANK_W) * Globals.TILE_W),
                (int)Math.Floor((decimal)(oi / Globals.TILEBANK_W) * Globals.TILE_W),
                (int)Globals.TILE_W,
                (int)Globals.TILE_W
            );

            Globals.SpriteBatch.Draw(tileBank, new Rectangle(x, y, Globals.TILE_W, Globals.TILE_H), tileRect, Color.White);
        }
    }

}

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles