Xnapooladdpooltable

You’ll need to:
• Create a new texture to hold the image
• Load the texture in during the LoadResources() method.
• Display it on the screen during the Draw() method (make sure you add this between your Begin and End spriteBatch calls.
During this draw stage you may come across some problems:
• If you can’t see your ball anymore then you’ll need to change the order that the ball and the table are drawn in.
• Your pool table image may move around with the ball (this is because you’ve used the SpritePosition that updates with moving ball)
• You’ll probably find that our pool table image is a different size from the window size.

code.png

To fix these last two issues we’ll need a different version of the Draw() method. As you can see Intellisense tells us there are 7 different versions of SpriteBatch.Draw. The first one is suitable for our purposes. All that has changed from our previous call is to pass in a Rectangle instead of a Vector2.

A Rectangle is used to specify the size that the image should be scaled to when drawn on the screen. Therefore, create a Rectangle that is the same size as our window (mine is 800 by 600) and pass this in to the Draw method.

e.g. "spriteBatch.Draw(imageName, new Rectangle(0,0,800,600), Color.White);"

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.