title: SFML - Rotating a sprite around its center using a Transform
body: <p>I have an object that needs to be able to be rotated around its center, but keeping the same origin (for setting position, etc). So, I figured I needed to use a <code>Transform.</code> </p>
  
  <p>Code is in Java (JSFML), but I figured the syntax was similar and able to be understood by anyone familiar with SFML. </p>
  
  <pre><code>public class DoorTile extends Tile {
  
      private Transform t;
  
      public DoorTile() {
          ...
          t = new Transform();
          ...
          sprite.setTexture(TileTextures.DOORTEXTURE);
      }
  
      public void rotateAroundCenter(float degrees) {
          Vector2f center = SpriteUtils.getTextureCenter(TileTextures.DOORTEXTURE);
          t = Transform.rotate(t, degrees, center.x, center.y);
      }
  
      @Override
      public void draw(RenderTarget rt, RenderStates states) {
          RenderStates newStates = new RenderStates(Transform.combine(t, states.transform));
          sprite.draw(rt, newStates);
      }
  </code></pre>
  
  <p><code>getTextureCenter(Texture t)</code> returns the center coordinates of <code>t</code>.</p>
  
  <p>Now, when I apply this rotation, my sprites have a weird behavior. At first, using 45 degrees as a test, they completely disappeared from the screen. So then I tried 1 degree. The sprites affected seemed to have pieces "cut off" and translated downward. 
  Here's a picture, using 1 degree as an argument:</p>
  
  <p><img src="https://i.stack.imgur.com/4au91.png" alt="Sprites affected are the little white things."></p>
  
  <p>For context, I'm trying to rotate those white sprites (will be 'doors') so they fit properly in the corridor. E.g. horizontal on vertical cooridors, vertical on horizontal corridors. (The white part of the sprite is a placeholder for transparency, that's just there for debugging purposes.)</p>
  
  <p>What should I do to be able to make this work properly? That is, how can I:</p>
  
  <ol>
  <li>Rotate a sprite around its center</li>
  <li>Keep the original origin (top left corner)</li>
  </ol>