Im trying to implement a proper Camera into my Game. At the moment i have some Gameobjects with an Image component and i subtract the Render Position of the Image with the Camera position. The problem is when i zoom into the game my Camera moves into the left corner. What i want to is that the Camera stay at the position where i have zoomed in.
Code:
tRect.x = Convert.ToInt32(((_ParentTransform.GetPosition().X * Camera.Camera.Instance._Scale.X) - (_Width * Camera.Camera.Instance._Scale.X)/2) - Camera.Camera.Instance._Scale.X * (Camera.Camera.Instance._Position.X ) );
tRect.y = Convert.ToInt32(((_ParentTransform.GetPosition().Y * Camera.Camera.Instance._Scale.Y) - (_Height * Camera.Camera.Instance._Scale.Y)/2) - Camera.Camera.Instance._Scale.Y * (Camera.Camera.Instance._Position.Y) );
tRect.h = (int)(_Height * Camera.Camera.Instance._Scale.X);
tRect.w = (int)(_Width * Camera.Camera.Instance._Scale.Y);
_Height, _Width is my Image Size.
while (SDL.SDL_PollEvent(out e) != 0)
{
switch (e.type)
{
case SDL.SDL_EventType.SDL_QUIT:
SDL.SDL_Quit();
Environment.Exit(0);
break;
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
if (e.wheel.y > 0)
{
Camera.Camera.Instance._Scale.X += .05f;
Camera.Camera.Instance._Scale.Y += .05f;
}
else if (e.wheel.y < 0)
{
Camera.Camera.Instance._Scale.X -= .05f;
Camera.Camera.Instance._Scale.Y -= .05f;
}
break;
}
}
I update the Camera position to its parent.The start position is (0, 0).
public void Update(float deltaTime)
{
_Position = _Parent.GetComponent<TransformComponent>().GetPosition();
}