1
\$\begingroup\$

I encountered a strange RenderTarget issue, in XNA/Monogame.

I am currently updating my render target at every frame, just to test to see what is happening. When I move the camera around, the positioning of the drawing inside of my rendertarget moves as well.

Notice in the example, how the image moves inside of my render target: Example

Here is the code for the Render Target draw:

GraphicsDevice.SetRenderTarget(Render);
RoundLineManager.Draw(Branches.GetAllObjects(), new Color(102, 50, 18), Matrix.Identity * Camera.View * Camera.Projection, RoundLineManager.TechniqueNames[0]);
SpriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, Camera.View);

foreach (Pool<Leaf>.Node l in Leaves.ActiveNodes)
    if (l.Item.Visible)
        l.Item.Draw();

SpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);

Here is the related Camera properties:

public Matrix View
{
    get
    {
        return Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
                Matrix.CreateRotationZ(Rotation) *
                Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
                Matrix.CreateTranslation(new Vector3(ViewportWidth * 0.5f + shakeOffset.X, ViewportHeight * 0.5f + shakeOffset.Y, 0));
    }
}

public Matrix Projection
{
    get
    {
        return Matrix.CreateOrthographicOffCenter(0, Infinidrill.GraphicsDevice.Viewport.Width, Infinidrill.GraphicsDevice.Viewport.Height, 0, 0, 1);
    }
}
\$\endgroup\$
1
\$\begingroup\$

Ok, it was my View property of the Camera class that was causing it. Really tired today, ugh. Here is the updated code:

public Matrix View
{
    get
    {
        return Matrix.CreateTranslation(new Vector3(GraphicsDevice.Viewport.Width * 0.5f, GraphicsDevice.Viewport.Height * 0.5f, 0));
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .