TestBox9Sprite.h 1.6 KB

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