本文介绍了xna 中 spritebatch.draw 中的源矩形是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SpriteBatch.Draw() 方法中源矩形参数的用途是什么?

MSDN 说:一个矩形,它指定(以纹素为单位)来自纹理的源纹素.使用null绘制整个纹理.

这是什么意思?

解决方案

sourceRectangle 的想法是允许您通过安排多个 sprites 变成单个 纹理.这被称为纹理图集".或精灵表".


I explain why it is a performance optimisation in this answer. Basically it lets you reduce the number of texture-swaps. (So in the case of my illustration, if you're only drawing an animated character once, using a sprite-sheet will not improve performance.)

It also lets you implement tacky 2D special effects, like having a sprite "wipe" in:


A texel is more-or-less the same thing as a pixel in the texture (a "texture pixel", if you will). So, when you draw your sprite, you specify the top-left corner of your sprite within the texture, along with its width and height. (The same as if you selected it in an image editor.)

If you pass in null for your source rectangle, XNA will assume a source rectangle that covers the entire texture.

The origin you specify to Draw is also measured in texels from the upper-left corner of the source rectangle.

这篇关于xna 中 spritebatch.draw 中的源矩形是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 06:44