我想知道这是否正确或是否应该更改?
我计划在我想改变我在主代码中绘制的瓷砖数量时调用这些,或者每当我想改变我的渲染目标时调用它们。基本上我想要自由去嘿嘿给我一个表面并且有任何类型的表面返回给我。无需担心启动它
我的这段代码中还有另一个问题:我返回的表面是否会实例化一个新的 COPY,或者我是否会获得从实例化它的函数中创建的相同实例。谢谢你。
我还需要知道我是否调用了 new_texture,然后我对那个纹理表面进行了一堆 spritebatch,然后我决定,好吧,现在我不想只拥有它我想渲染它。当我在绘图循环结束后从我的绘图函数中调用 base.draw() 会发生什么时,我在 game.draw() 之前调用两组 spritebatches,其中 spritebatches 必须渲染到一个表面纹理,然后另一个,按特定顺序?我的渲染顺序会混乱还是无关紧要?这样做的任何替代方法,我愿意接受建议吗?
另一个问题,当我调用 draw_texture 函数时,它告诉我图形设备为空。我不知道为什么!!!!
这是代码
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
namespace TileEngine
{
class Renderer
{
GraphicsDevice mydevice;
public SpriteBatch spriteBatch;
RenderTarget2D new_texture(int width, int height, RenderTarget2D Mine)
{
Texture2D TEX = new Texture2D(mydevice, width, height); //create the texture to render to
mydevice.SetRenderTarget(Mine); //set the render device to the reference provided
//maybe base.draw can be used with spritebatch. Idk. We'll see if the order of operation
//works out. Wish I could call base.draw here.
return Mine; //I'm hoping that this returns the same instance and not a copy.
}
void draw_texture(int width, int height, RenderTarget2D Mine)
{
mydevice.SetRenderTarget(null); //Set the renderer to render to the backbuffer again
Rectangle drawrect = new Rectangle(0, 0, width, height); //Set the rendering size to what we want
spriteBatch.Begin(); //This uses spritebatch to draw the texture directly to the screen
spriteBatch.Draw(Mine, drawrect, Color.White); //This uses the color white
spriteBatch.End(); //ends the spritebatch
//Call base.draw after this since it doesn't seem to recognize inside the function
//maybe base.draw can be used with spritebatch. Idk. We'll see if the order of operation
//works out. Wish I could call base.draw here.
}
}
}