Guest User

Untitled

a guest
Jul 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6.  
  7. using BaconEngine.GameComponents;
  8.  
  9. namespace BaconEngine
  10. {
  11. public class Camera
  12. {
  13. #region Fields and Properties
  14. public Vector2 Position;
  15. float speed = 8f;
  16. public float Speed
  17. {
  18. get { return speed; }
  19. set { speed = MathHelper.Clamp(speed, 1.0f, 16.0f); }
  20. }
  21. #endregion
  22.  
  23. #region Constructors
  24.  
  25. public Camera()
  26. {
  27. Position = Vector2.Zero;
  28. }
  29.  
  30. public Camera(Vector2 position)
  31. {
  32. Position = position;
  33. }
  34. #endregion
  35.  
  36. #region Methods
  37.  
  38. public void LockCamera()
  39. {
  40. Position.X = MathHelper.Clamp(Position.X, 0, TileMap.WidthInPixels - Engine.ViewportWidth);
  41. Position.Y = MathHelper.Clamp(Position.Y, 0, TileMap.HeightInPixels - Engine.ViewportHeight);
  42. }
  43.  
  44. public void LockToSprite(AnimatedSprite sprite)
  45. {
  46. Position.X = sprite.Position.X + sprite.Width / 2
  47. - (Engine.ViewportWidth / 2);
  48. Position.Y = sprite.Position.Y + sprite.Height / 2
  49. - (Engine.ViewportHeight / 2);
  50. }
  51.  
  52. #endregion
  53. }
  54. }
Add Comment
Please, Sign In to add comment