Esempio n. 1
0
        /// <summary>
        /// Update method to focus camera on player that is passed.
        /// Point of focus is center of sprite image.
        /// </summary>
        /// <param name="map">Used to keep camera from going off the map.</param>
        /// <param name="player">Player to focus camera on.</param>
        public void Update(TileMap map, Player player)
        {
            position.X = player.Position.X + (player.Width / 2 - screenWidth / 2);
            position.Y = player.Position.Y + (player.Height / 2 - screenHeight / 2);

            position.X = MathHelper.Clamp(position.X, 0.0f, map.Width - screenWidth);
            position.Y = MathHelper.Clamp(position.Y, 0.0f, map.Height - screenHeight);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates position of player, bounding it to the map.
        /// </summary>
        /// <param name="map">Map to bound player to.</param>
        public void Update(TileMap map)
        {
            pos += Velocity;

            pos.X = MathHelper.Clamp(pos.X, 0f, map.Width - fWidth);  //Remove "fWidth" to allow player to move offscreen at far right.
            pos.Y = MathHelper.Clamp(pos.Y, 0f, map.Height - fHeight);  //Remove "fHeight" to allow player to move offscreen at far bottom.
        }