Advertisement
erzis

Untitled

Dec 28th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include "Character.h"
  3.  
  4. Character::Character()
  5. {
  6. texture.loadFromFile("images/char2.png");
  7. chSprite = sf::Sprite(texture);
  8.  
  9. chSprite.setTextureRect(sf::IntRect(0, 0, 130, 130));
  10. chSprite.setPosition(300.0, 300.0);
  11. }
  12.  
  13. void Character::Move(int Direction)
  14. {
  15. sf::Vector2f offset;
  16. switch (Direction)
  17. {
  18. case 0:
  19. offset.x = 0;
  20. offset.y = 10;
  21. break;
  22. case 1:
  23. offset.x = -10;
  24. offset.y = 0;
  25. break;
  26. case 2:
  27. offset.x = 0;
  28. offset.y = -10;
  29. break;
  30. case 3:
  31. offset.x = 10;
  32. offset.y = 0;
  33. break;
  34. }
  35. chSprite.move(offset);
  36. chSprite.setTextureRect(sf::IntRect(0 * 100, Direction * 130, 130, 130));
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement