开发者

XNA - Global Zoom

开发者 https://www.devze.com 2023-03-08 16:52 出处:网络
I\'m trying to allow zoom with the mouse scroll and pass a zoom value into each of my drawable object开发者_运维知识库s. Each drawable object takes the zoom value and uses the scale parameter of the S

I'm trying to allow zoom with the mouse scroll and pass a zoom value into each of my drawable object开发者_运维知识库s. Each drawable object takes the zoom value and uses the scale parameter of the SpriteBatch.Draw method. Zooming each individual item though doesn't work in relation to all other objects. Is there some sort of canvas I can draw everything to, and then zoom that so everything zooms appropriately?


Use the SpriteBatch.Begin method that takes a Matrix parameter. Pass a scaling matrix:

Matrix scaleMatrix = Matrix.CreateScale(myScale);
sb.Begin(SpriteSortMode.Deferred, null, null, null, null, null, scaleMatrix);

You should use this parameter for all "global" transformations of your sprites. So you could combine (multiply) a translation and a scale matrix to move about and zoom your 2D scene.


In the camera, you have to re-create the view , changing the field of view to a smaller value:

Matrix.CreatePerspectiveFieldOfView(
    MathHelper.PiOver4,                    // change this to, say 20°
    aspectRatio,
    0.0001f,
    1000.0f,
    out projection
);

Now this change is global since you use camera's projection in your effects

0

精彩评论

暂无评论...
验证码 换一张
取 消