I'm currently working on a 2d isometric tile-based game with a camera and the functionality to zoom in and out. So far I'll take the center of the screen as "zoom point" using the following lines of code which works totally fine:

public static Matrix SetTransformation(Vector2 loc, Vector2 pos)
    // Set translation values.
    translatedLocation.X = -loc.X;
    translatedLocation.Y = -loc.Y;
    translatedLocation.Z = 0;

    translatedScale.X = Scale;
    translatedScale.Y = Scale;
    translatedScale.Z = 1;

    translatedPosition.X = pos.X;
    translatedPosition.Y = pos.Y;
    //translatedPosition.X = MousePosition.X;
    //translatedPosition.Y = MousePosition.Y;
    translatedPosition.Z = 0;

    // Set transform by current location.
    Transform = Matrix.CreateTranslation(-Location) *
                Matrix.CreateScale(translatedScale) *

    return Transform;

SetTransformation() is called in my Update() function. When I remove the commented lines above I get the behavior I'm looking for except for the fact that the camera always follows the Mouse position and not only while zooming. Each try only recognizing the Mouse position during the zoom activity had the result that the camera jumped to a different location when zooming has been completed.

I've looked though similar questions here but I haven't found a solution yet. Anybody here to help me out on this issue?

Thanks in advance!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.