gpt4 book ai didi

c# - 在 XNA 中使用 Draw 方法旋转 Texture2D?

转载 作者:行者123 更新时间:2023-11-30 16:25:17 24 4
gpt4 key购买 nike

旋转有问题。我知道我可以使用 draw 方法旋转 Texture2D 对象。

我的目标是将纹理旋转 180°。例如,如果我用头部在底部的相机拍摄一个人的照片,我希望能够旋转它以便头部再次在顶部。

这是代码或旋转:

spriteBatch.Draw(Texture, Position, null, Color.White, MathHelper.Pi, new Vector2(), 1.0f, SpriteEffects.None, 0f);

旋转工作正常,但我有另一个问题: enter image description here

如果我在旋转后将纹理添加到位置 0,0,它就不再可见了。

如何旋转或反射对象,使红点再次位于左上角?

最佳答案

http://msdn.microsoft.com/en-us/library/ff433989.aspx

public void Draw (
Texture2D texture,
Vector2 position,
Nullable<Rectangle> sourceRectangle,
Color color,
float rotation,
Vector2 origin,
Vector2 scale,
SpriteEffects effects,
float layerDepth)

//Using:
var origin = new Vector2()
{
X = texture.Width / 2,
Y = texture.Height/ 2
};


spriteBatch.Draw(texture, Vector2.Zero, null, Color.White, MathHelper.Pi, origin, 1f, SpriteEffects.None, 0f)`

关于c# - 在 XNA 中使用 Draw 方法旋转 Texture2D?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10102113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com