views:

15

answers:

1

I am pretty good at programming, however, i am new to c# (xna), i am following a tutorial to draw a sprite on screen and the blendstate method is not recognized when used like the following in the draw method:

protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            // Draw the sprite.
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); 

//doesnt recognize blendstate (puts squiggles under it)

            spriteBatch.Draw(myTexture, spritePosition, Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }

thanks in advance as this is definately bothering me.

+1  A: 

My first thought is: What happens if you mouse-over the error? It should give you a tool-tip with the text telling you what the actual error is.

Additionally, if you haven't got using Microsoft.Xna.Framework.Graphics at the top of your source file (but you have got Microsoft.Xna.Framework.Graphics.dll referenced by the project, which you also need), it will also give you a little box to click to add in that using statement (I believe the shortcut key to make it pop up is Ctrl-Shift-F10).

Also you could just pass in null instead of BlendState.AlphaBlend, as that is the default blend state (see the documentation).


My second thought is that you're using an XNA 4.0 tutorial with an older version of XNA. Are you? This blog post explains the differences in SpriteBatch.

Andrew Russell
I do have the code using Microsoft.Xna.Framework.Graphics at the top of my code, however, i could not find anything saying that i had that reference implemented. How would i do this? i right-click on references and click new reference and i double-click Microsoft.Xna.Framework and it doesnt help.The error(when i mouse-over the error) is this: Error 1 The name 'Blendstate' does not exist in the current contextthank you, and ps, when i put 'BlendState.AlphaBlend' as 'null', it gives me this error:Error 1 No overload for method 'Begin' takes '2' arguments
Custard
@Custard: I have updated my answer. I think your XNA versions are mismatched.
Andrew Russell
Haha wow, thanx :) ya that was the problem.
Custard