RaptorExample.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2.3
  4. *
  5. * Copyright (c) 2013-2015, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to use, install, execute and perform the Spine
  10. * Runtimes Software (the "Software") and derivative works solely for personal
  11. * or internal use. Without the written permission of Esoteric Software (see
  12. * Section 2 of the Spine Software License Agreement), you may not (a) modify,
  13. * translate, adapt or otherwise create derivative works, improvements of the
  14. * Software or develop new applications using the Software or (b) remove,
  15. * delete, alter or obscure any trademarks or any copyright, trademark, patent
  16. * or other intellectual property or proprietary rights notices on or in the
  17. * Software, including any copy thereof. Redistributions in binary or source
  18. * form must include this license and terms.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  21. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  23. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  26. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  28. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  29. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *****************************************************************************/
  31. #include "RaptorExample.h"
  32. #include "TankExample.h"
  33. USING_NS_CC;
  34. using namespace spine;
  35. Scene* RaptorExample::scene () {
  36. Scene *scene = Scene::create();
  37. scene->addChild(RaptorExample::create());
  38. return scene;
  39. }
  40. bool RaptorExample::init () {
  41. if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;
  42. skeletonNode = SkeletonAnimation::createWithFile("raptor.json", "raptor.atlas", 0.5f);
  43. skeletonNode->setAnimation(0, "walk", true);
  44. skeletonNode->setAnimation(1, "empty", false);
  45. skeletonNode->addAnimation(1, "gungrab", false, 2);
  46. skeletonNode->setPosition(Vec2(_contentSize.width / 2, 20));
  47. addChild(skeletonNode);
  48. scheduleUpdate();
  49. EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
  50. listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
  51. if (!skeletonNode->getDebugBonesEnabled())
  52. skeletonNode->setDebugBonesEnabled(true);
  53. else if (skeletonNode->getTimeScale() == 1)
  54. skeletonNode->setTimeScale(0.3f);
  55. else
  56. Director::getInstance()->replaceScene(TankExample::scene());
  57. return true;
  58. };
  59. _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
  60. return true;
  61. }