View Single Post
  #7 (permalink)  
Old February 21st, 2009, 04:12 PM
philip_cole philip_cole is offline
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts

Hi tkn_one,

As the paragraph above the RenderSprite code says, sourceRect is of type Nullable Rectangle, not a normal Rectangle, i.e. it could be null. This measn you cannot call Width directly from it. Instead you have to use the Value property (defined in the Nullable type) to get the actual rectangle if there is one. SO you would say something like:

Aside from that the DrawSprites method in the book is using the Width and Height of the sprite.rect, not the sourceRect, which is simply passed along to the spriteBatch.Draw method. So make sure you aren't getting the two mixed up.
Hope this helps

P.S. to start a new thread, go the main forum page for the book, and press the blue "New Thread" button just above the table of threads.