我想翻转图像并为翻转后的图像创建一个新的Texture2D。
我做了一些研究,发现这段代码将创建一个新的Texture2D;
RenderTarget2D newTarget = new RenderTarget2D(GraphicsDevice, partWidth, partHeight)
GraphicsDevice.SetRenderTarget(newTarget);
SpriteBatch.Draw(original, Vector2.Zero, partSourceRectangle, ... )
GraphicsDevice.SetRenderTarget(null);
Texture2D newTexture = (Texture2D)newTarget;
Run Code Online (Sandbox Code Playgroud)
我知道 newTexture 很容易从内存中删除,因此建议我需要使用 getData/SetData 来创建更永久的纹理。有人可以建议我执行此操作的具体语法吗?
我有以下设置;
public abstract class StageObject
{
}
public class StageImage : StageObject
{
public int Image;
}
public class StageStrip : StageObject
{
public int Strip;
}
Run Code Online (Sandbox Code Playgroud)
我做以下事情;
StageList = new List<StageObject>();
StageList.Add(new StageStrip());
StageList.Add(new StageImage());
Run Code Online (Sandbox Code Playgroud)
我希望能够像这样投射数组元素这样的具体类型,但是我得到了一个错误;
(StageStrip) StageList[0].Strip = 2;
Run Code Online (Sandbox Code Playgroud)
我能做到这一点的唯一方法是创建一个临时变量并将其强制转换为数组.有没有办法可以在不创建临时变量的情况下完成?