Rotating a Sprite around it's center
in
Programming Questions
•
1 year ago
Hi,
I have searched on these forums, looked at examples but whatever I try, I can not get my head around rotating a sprite. I have a sprite class with an X and Y position and a faceAngle (the direction the sprite is facing, 0 = default).
I wish to implement a public void to allow rotation of a Sprite object on a per-object basis. I can get the sprites to rotate around their top-left & top-right coordinates, but seem to be unable to make them rotate around their centers.
My SpriteClass:
http://pastebin.com/3idaiejT
My rotation method (it seems to modify the Object's X and Y position because if I scroll the screen right ( I am using this in a sidescroller game) the Sprite follows the player/screen whilst it should remain at a fixed point on the screen):
Thanks for any help in advance!
- void rotateMe(int deg) {
- pushMatrix();
- this.faceAngle += deg;
- //this.faceAngle = constrain(this.faceAngle, 0, 360);
- //translate(this.X + this.sprite.width / 2, this.Y + this.sprite.height / 2);
- rotate(radians(this.faceAngle));
- render();
- popMatrix();
- }
1