Monogame XNA transform matrix for a single object?

落爺英雄遲暮 提交于 2020-01-15 12:38:12

问题


I have read a few tutorials explaining transform matrices for XNA/Monogame. The problem is that these matrices are applied to

SpriteBatch.Begin(...matrix);

This means that all Draw code will be transformed. How do I apply a transformation matrix to a single drawable object? In my case I want to transform a scrolling background so that it automatically wraps.

SpriteBatch.Draw(.. this has no transform matrix parameter?);

回答1:


If you want to use a specific spritebatch begin call for some drawing calls only, you can start a new one as needed.

for example

SpriteBatch.Begin(...matrix);

//Draw stuff with matrix

SpriteBatch.End();

SpriteBatch.Begin();

//do the rest of the drawing

SpriteBatch.End();

this is commonly used to draw a bunch of objects with a "camera" matrix at appropraite position, scale and rotation, then another spritebatch.Begin is called to draw the flat, static UI on top, etc.



来源:https://stackoverflow.com/questions/30460072/monogame-xna-transform-matrix-for-a-single-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!