Note that there are some explanatory texts on larger screens.

plurals
  1. POXNA spritebatch and primative using different axis with same effect
    text
    copied!<p>I am developing a side scroller game using monogame 3.0 (XNA-C#). I am using a TriangleStrip to draw the ground and a spritebatch to draw a fence. I want the fence to be on top of the ground but it seems to be using a different axis (negative instead of positive). In order to align things up I need to flip the fence and use a negative x and y. Both the sprite and the primitive are using the same view matrix and project.</p> <p>Why is the spritebatch need a negative axis while the primitive is using a positive one when they are using the same matrixes? </p> <pre class="lang-cs prettyprint-override"><code>protected override void Initialize() { viewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, 1), Vector3.Zero, new Vector3(0,1, 0)); projectionMatrix = Matrix.CreateOrthographicOffCenter(0,GraphicsDevice.Viewport.Width, 0, GraphicsDevice.Viewport.Height, 0f, 200f) *Matrix.CreateScale(new Vector3(.5f, .5f, 1f)); GraphicsDevice.RasterizerState.CullMode = CullMode.None; _groundBasicEffect = new BasicEffect(GraphicsDevice); _groundBasicEffect.View = viewMatrix; _groundBasicEffect.Projection = projectionMatrix; _groundBasicEffect.VertexColorEnabled = true; _groundBasicEffect.World = world; _fenceBasicEffect = new BasicEffect(GraphicsDevice); _fenceBasicEffect.View = Matrix.CreateLookAt(new Vector3(0, 0, 1), Vector3.Zero, new Vector3(0,1, 0)); _fenceBasicEffect.Projection = projectionMatrix; _fenceBasicEffect.TextureEnabled = true; _fenceBasicEffect.World = world; base.Initialize(); } protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); fenceTexture = this.Content.Load&lt;Texture2D&gt;(@"Fence1"); vertexData = new VertexPositionColor[8]; vertexData[0] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Black); vertexData[1] = new VertexPositionColor(new Vector3(0, 400, 0), Color.Black); vertexData[2] = new VertexPositionColor(new Vector3(200, 0, 0), Color.Black); vertexData[3] = new VertexPositionColor(new Vector3(200, 400, 0), Color.Black); vertexData[4] = new VertexPositionColor(new Vector3(300, 0, 0), Color.Black); vertexData[5] = new VertexPositionColor(new Vector3(300, 430, 0), Color.Black); vertexData[6] = new VertexPositionColor(new Vector3(1200, 0, 0), Color.Black); vertexData[7] = new VertexPositionColor(new Vector3(1200, 430, 0), Color.Black); vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), vertexData.Length, BufferUsage.None); vertexBuffer.SetData(vertexData); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.White); GraphicsDevice.SetVertexBuffer(vertexBuffer); _groundBasicEffect.CurrentTechnique.Passes[0].Apply(); GraphicsDevice.DrawUserPrimitives&lt;VertexPositionColor&gt;(PrimitiveType.TriangleStrip, vertexData, 0, vertexData.Length -2); _spriteBatch.Begin(0, null, null, null, null, _fenceBasicEffect); _spriteBatch.Draw(fenceTexture, Vector2.Zero, new Rectangle(0, 0, 1130, 221), Color.White, 0, new Vector2(0, 200), 1, SpriteEffects.None, 0); _spriteBatch.End(); base.Draw(gameTime); } </code></pre> <p><strong>How it looks...</strong> <img src="https://i.stack.imgur.com/v3IEz.png" alt="How it looks"></p> <p><strong>How I expect it to look...</strong> <img src="https://i.stack.imgur.com/EcY9y.png" alt="How I expect it to look"></p> <p>In order to get this look I need to change the Draw of the fence to this...</p> <pre><code>_spriteBatch.Draw(fenceTexture, Vector2.Zero, new Rectangle(0, 0, 1130, 221), Color.White, 0, new Vector2(0, -400), 1, SpriteEffects.FlipVertically, 0); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload