Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

When I added a Rectangle to the Draw method for the sprite, it did not show up on screen.

 spriteBatch.Draw(texture, position, new Rectangle((int)position.X, (int)position.Y, (int)texture.Width, (int)texture.Height), Color.White, rotation, orgin, scale, SpriteEffects.None, 0f);
share|improve this question
    
have you called spriteBatch.begin() and spriteBatch.end()? –  AbstractChaos Jul 13 '12 at 9:58
add comment

1 Answer

up vote 2 down vote accepted

The third parameter specifies which parts of the sprite you wish to draw.

From MSDN:

sourceRectangleType: Rectangle?

A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture.

You should change your code to something like this:

  spriteBatch.Draw(texture, position, new Rectangle(0, 0, (int)texture.Width, (int)texture.Height), Color.White, rotation, orgin, scale, SpriteEffects.None, 0f);    

This parameter is useful if you're using spritesheets (image files with multiple sprites in them).

share|improve this answer
    
Thanks! It works! But while I searched the net, I found some info about problems with collsion detection if the object i rotation? Is the rectangle also rotation? All my objects a like a square with equal width and height, will this not work? –  3D-kreativ Jul 13 '12 at 10:18
    
Well, that's a whole different question. It really depends on how you manage your collisions. This Rectangle is independent from the sprite's MinimalBoundingRectangle. If you have problems regarding rotation, collision detection and MBR's, then use the search. –  Marton Jul 13 '12 at 10:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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