TestBox9Sprite.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include "test.h"
  3. #include "Box9Sprite.h"
  4. class TestBox9Sprite: public Test
  5. {
  6. public:
  7. spBox9Sprite _sprite;
  8. TestBox9Sprite()
  9. {
  10. ResAnim* rs = resources.getResAnim("box9a");
  11. spSprite original = new Sprite;
  12. original->setPosition(10, 70);
  13. original->setResAnim(rs);
  14. addChild(original);
  15. spBox9Sprite sprite;
  16. sprite = new Box9Sprite;
  17. sprite->setPosition(270, 50);
  18. sprite->setResAnim(rs);
  19. sprite->setSize(300, 250);
  20. sprite->setVerticalMode(Box9Sprite::STRETCHING);
  21. sprite->setHorizontalMode(Box9Sprite::STRETCHING);
  22. sprite->addTween(Actor::TweenWidth(getWidth() - sprite->getX() - 190), 5000, -1, true);
  23. sprite->addTween(Actor::TweenHeight(getHeight() - sprite->getY() - 10), 5000, -1, true, 2500);
  24. //You could also define guides from xml
  25. //<image file="box9.png" guideX1="50" guideX2="210" guideY1="50" guideY2="125" />
  26. sprite->setGuides(40, 160, 40, 160);
  27. addChild(sprite);
  28. _sprite = sprite;
  29. Test::toggle tg[] =
  30. {
  31. Test::toggle("switch to TILING_FULL", Box9Sprite::TILING_FULL),
  32. Test::toggle("switch to TILING", Box9Sprite::TILING),
  33. Test::toggle("switch to STRETCHING", Box9Sprite::STRETCHING),
  34. };
  35. addToggle("ver. mode", tg, 3);
  36. addToggle("hor. mode", tg, 3);
  37. }
  38. void toggleClicked(string id, const toggle* t)
  39. {
  40. if (id == "ver. mode")
  41. _sprite->setVerticalMode(Box9Sprite::StretchMode(t->value));
  42. if (id == "hor. mode")
  43. _sprite->setHorizontalMode(Box9Sprite::StretchMode(t->value));
  44. }
  45. };