esgargs

Greetings,

I followed the second XNA tutorial, and got to creating a scrolling background for the space ship program. My problem is that as soon as I added the code from the tutorial for the scrolling background, the space ship became somewhat transparent, meaning that I am not seeing it like a solid rather a sum total of spheres and other geometries. For example, I can now see the 4 spheres on the surface of the ship in their entirety, and also the scrolling background behind it. Can someone help me out here

Thanks!


Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

ProfEclipse

What tutorial are you talking about The tutorials in the XNA documentation don't do any scrolling background.





Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

esgargs

http://msdn2.microsoft.com/en-us/library/16ed4c9-d98b-ff53-8f5c-ab2e6a4d5daf.aspx

This is referenced in the first 3D tutorial in the XNA Getting Started Tutorial.




Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

ProfEclipse

Ah. That's very different.

Did you make sure to follow the "Hint: Make sure you use a call to SpriteBatch.Draw that allows you to specify a layerDepth parameter, and set that depth to 1.0f "

It sounds like your background is being drawn at z=0.0. Since the ship is also drawn at z=0.0, parts of the ship would be behind the background. What happens if you move the ship toward or away from the camera





Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

esgargs

Yep, the Batch.draw statements in that tutorial use the layerDepth parameter, and even after playing around with the values, my ship is still translucent.

I am new at this, and have a feeling that the BasicEffect.Projection method might have something to do with it. I tried moving the ship around on the Z axis, but it still remains translucent.

Thanks.




Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

BlueG

I just tried it and got the same thing. The problem is that the SpriteBatch class is changing the render state of the device. I worked around it by placing the following line right after my SpriteBatch.Begin call:

[code]

StateBlock state = new StateBlock( graphics.GraphicsDevice );

[/code]

and then the following line right after my SpriteBatch.End call:

[code]

state.Apply();

[/code]

Once I figure out what its setting (it has to be one of the alpha parameters), I'll let you know. It wasn't my first guess... but there are only a few that it could be and generating a StateBlock every frame this way might not really be a good idea.






Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

Pange

SpriteBatch.Begin() also has an option to save the render state



Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

ProfEclipse

Pange wrote:
SpriteBatch.Begin() also has an option to save the render state

That's the ticket.





Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

BlueG

So it does. And saving the render state really isn't a problem I'm finding. I should know that from DX and MDX, but I was worried over a little blurb in thier documentation.

It also turns out that it was the RenderState.DepthBufferEnabled property that was the primary culprit. I kept looking at alpha blending properties, though AlphaBlendEnabled also caused it to be slightly transparent.

So, the three options to fix are: A) have SpriteBatch.Begin save the render state by changing it to be something like:

backgroundBatch.Begin( SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState );

or, B) after the call to the SpriteBatch.End method, clear the AlphaBlendEnable property and set the DepthBufferEnable property as follows:

graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false;
graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;

or, C) save the render state yourself as in my first response, but, then why wouldn't you just have the Begin method do it

Thanks, Page and Prof.






Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

esgargs

Thanks, BlueG.

That was very helpful.




Re: XNA Game Studio Express Issue with XNA Tutorial and scrolling backgrounds

auz1111

Awesome that did the trick!