RaptorExample.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated May 1, 2019. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2019, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
  19. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  21. * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
  24. * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  27. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #include "RaptorExample.h"
  30. #include "TankExample.h"
  31. #include <spine/Extension.h>
  32. USING_NS_CC;
  33. using namespace spine;
  34. PowInterpolation pow2(2);
  35. PowOutInterpolation powOut2(2);
  36. SwirlVertexEffect effect(400, powOut2);
  37. Scene* RaptorExample::scene () {
  38. Scene *scene = Scene::create();
  39. scene->addChild(RaptorExample::create());
  40. return scene;
  41. }
  42. bool RaptorExample::init () {
  43. if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;
  44. skeletonNode = SkeletonAnimation::createWithJsonFile("raptor-pro.json", "raptor.atlas", 0.5f);
  45. skeletonNode->setAnimation(0, "walk", true);
  46. skeletonNode->addAnimation(1, "gun-grab", false, 2);
  47. skeletonNode->setTwoColorTint(true);
  48. effect.setCenterY(200);
  49. swirlTime = 0;
  50. skeletonNode->setVertexEffect(&effect);
  51. skeletonNode->setPosition(Vec2(_contentSize.width / 2, 20));
  52. addChild(skeletonNode);
  53. scheduleUpdate();
  54. EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
  55. listener->onTouchBegan = [this] (Touch* touch, cocos2d::Event* event) -> bool {
  56. if (!skeletonNode->getDebugBonesEnabled()) {
  57. skeletonNode->setDebugBonesEnabled(true);
  58. skeletonNode->setDebugMeshesEnabled(true);
  59. } else if (skeletonNode->getTimeScale() == 1)
  60. skeletonNode->setTimeScale(0.3f);
  61. else
  62. Director::getInstance()->replaceScene(TankExample::scene());
  63. return true;
  64. };
  65. _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
  66. return true;
  67. }
  68. void RaptorExample::update(float fDelta) {
  69. swirlTime += fDelta;
  70. float percent = spine::MathUtil::fmod(swirlTime, 2);
  71. if (percent > 1) percent = 1 - (percent - 1);
  72. effect.setAngle(pow2.interpolate(-60.0f, 60.0f, percent));
  73. }