0
\$\begingroup\$

I'm looking for help fixing a small problem that I have with my XNA game project.

I currently have:

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
            null, null, null, null, camera.ViewMatrix);
        spriteBatch.Draw(Stone, TestPosition, Color.White);
        spriteBatch.Draw(Person, playerPosition, Color.White);
        spriteBatch.End();

and

spriteBatch.Begin(SpriteSortMode.Deferred,
              null, SamplerState.LinearWrap, null, null);
        spriteBatch.Draw(Grass, grassPosition,
             new Rectangle(0, 0, Grass.Width * 60, Grass.Height * 1),
             Color.White);
        spriteBatch.Draw(Stone, StonePosition,
             new Rectangle(0, 0, Stone.Width * 60, Stone.Height * 10),
             Color.White);

        spriteBatch.End();

I am looking to combine these two spriteBatch so that the stone and grass in the second spriteBatch will be affected by the viewmatrix.

I have tried:

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
                SamplerState.LinearWrap, null, null, null, camera.ViewMatrix);
            spriteBatch.Draw(Grass, grassPosition,
                 new Rectangle(0, 0, Grass.Width * 60, Grass.Height * 1),
                 Color.White);
            spriteBatch.Draw(Stone, StonePosition,
                 new Rectangle(0, 0, Stone.Width * 60, Stone.Height * 10),
                 Color.White);
            spriteBatch.Draw(Stone, TestPosition, Color.White);
            spriteBatch.Draw(Person, playerPosition, Color.White);
            spriteBatch.End();

However when I go to run the code, I get the following error:

XNA Framework Reach profile requires TextureAddressMode to be Clamp when using texture sizes that are not powers of two.

I hope that someone can help me achieve this, Thank You.

\$\endgroup\$
1
\$\begingroup\$

The error indicates that if you are using textures that are not powers of 2 (128x128, 256x256, etc), that you must set the SamplerState parameter of SpriteBatch.Begin to SamplerState.LinearClamp instead of SamplerState.LinearWrap.

Judging from your code it looks like Grass and Stone are powers of 2, but the Person is not.

To fix the problem you'll need to either change the Person texture to a power of two, use SamplerState.LinearClamp for everything you listed, or draw the Person texture with its own SpriteBatch.Begin and End using Sampler.LinearClamp and the rest that are powers of two using LinearWrap.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Or change from Reach to HiDef profile in the property settings of the project. \$\endgroup\$ – jgallant Oct 1 '14 at 13:32
  • \$\begingroup\$ Thanks, it's working great and thank you for your fast response. \$\endgroup\$ – Eric Coufmann Oct 1 '14 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.