This is probably a very easy question, but I can't seem to understand why it's not working.
I want the basketball to bounce horizontally when it touches the borders on the right and left, but when it bounces on the right, it seems to go just a little bit further than it should.
Any suggestions?
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
basketballPosition.X += ballSpeed;
if (basketballPosition.X > Window.ClientBounds.Width - basketball.Width || basketballPosition.X < 0)
{
ballSpeed *= -1;
}
base.Update(gameTime);
}
And my Draw method:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(basketball,
basketballPosition,
null,
Color.White,
0,
Vector2.Zero,
1.5f,
SpriteEffects.None,
0);
spriteBatch.End();
base.Draw(gameTime);
}
Edit The problem was I was using a scale of 1.5f for drawing the image. Can someone explain how I would get the true border of the image if I were using scale? It seems the border stay as the original size, but the texture is drawn to whatever scale I choose.