I'm wondering about if this is correct or if it should be changed?
I plan to call these whenever I want to do a change in how many tiles I'm drawing in my main code, or whenever I want to change my rendering target. Basically I want the freedom to go hey give me a surface and have a surface of any type returned to me. Without having to worry about initiating it
Also another question in this code of mine: Will the surface that I return, instantiate a new COPY, or will I be given the same instance that was created from within the function that instantiated it. Thank you.
I also need to know if I call new_texture, then I do a bunch of spritebatch to that texture surface then I decide, okay, now I dont want to just have it i want to render to it. When I call base.draw() after at the end of my drawing loop from within my draw function what will happen when, I call two sets of spritebatches before game.draw() where the spritebatches have to be rendered to one surface texture, then another one, in a specific order? Will the order of my rendering get messed up or will it not matter? Any alternatives to doing this , im open to suggestions?
one other issue, it tells me the graphics device is null when I call the draw_texture function. I don't know why!!!!
Here's the code
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.
}
}
}