Time for action – updating and drawing the player's ship
- Add the
imposeMovementLimits()
helper method to the PlayerManager class:private void imposeMovementLimits() { Vector2 location = playerSprite.Location; if (location.X < playerAreaLimit.X) location.X = playerAreaLimit.X; if (location.X > (playerAreaLimit.Right - playerSprite.Source.Width)) location.X = (playerAreaLimit.Right - playerSprite.Source.Width); if (location.Y < playerAreaLimit.Y) location.Y = playerAreaLimit.Y; if (location.Y > (playerAreaLimit.Bottom - playerSprite.Source.Height)) location.Y = (playerAreaLimit.Bottom - playerSprite.Source.Height); playerSprite.Location = location; }
- Add the
Update()
method to the PlayerManager class:public void Update(GameTime gameTime) { PlayerShotManager.Update(gameTime); ...
Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.