Hello guys,
I am currently writing a “Sprite” class and I have one problem with the origin and the coordinate system in general.
First of all I calculate the origin based on the code provided below but the origin seems to be always at the top left of the window (it rotates around the topleft of the screen all the time, no matter where my sprite is positioned).
Another problem I have is that the coordinate system seems to be off. Maybe this is intended but when I for example move my sprite to the right side of my window my x coordinate goes into negative. Shooldn’t it go into positive numbers? Same problem applys to Y.
Would be nice if anyone could help me get on the right track at least
private void ApplyChanges()
{
boundingRect.Width = (int)(texture.Width * scaleX);
boundingRect.Height = (int)(texture.Height * scaleY);
boundingRect.X = position.X;
boundingRect.Y = position.Y;
//Determines the origin based on originMode
switch (originMode)
{
case OriginMode.Center:
origin = new Vector2(position.X+(boundingRect.X + boundingRect.Width / 2) / scaleX, position.Y+(boundingRect.Y + boundingRect.Height / 2) / scaleY);
break;
case OriginMode.BottomLeft:
origin = new Vector2(position.X+boundingRect.X, position.Y+boundingRect.Y + boundingRect.Height);
break;
case OriginMode.BottomRight:
origin = new Vector2(position.X+boundingRect.X + boundingRect.Width, position.Y+boundingRect.Y + boundingRect.Height);
break;
case OriginMode.TopLeft:
origin = new Vector2(position.X+boundingRect.X, position.Y+boundingRect.Y);
break;
case OriginMode.TopRight:
origin = new Vector2(position.X+boundingRect.X + boundingRect.Width, position.Y+ boundingRect.Y);
break;
default:
break;
}
}