SpineboyExample.m 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, 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. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #import "SpineboyExample.h"
  30. #import "GoblinsExample.h"
  31. @implementation SpineboyExample
  32. + (CCScene*) scene {
  33. CCScene *scene = [CCScene node];
  34. [scene addChild:[SpineboyExample node]];
  35. return scene;
  36. }
  37. -(id) init {
  38. self = [super init];
  39. if (!self) return nil;
  40. skeletonNode = [SkeletonAnimation skeletonWithFile:@"spineboy-pro.json" atlasFile:@"spineboy.atlas" scale:0.4];
  41. [skeletonNode setMixFrom:@"walk" to:@"jump" duration:0.2f];
  42. [skeletonNode setMixFrom:@"jump" to:@"run" duration:0.2f];
  43. __weak SkeletonAnimation* node = skeletonNode;
  44. skeletonNode.twoColorTint = true;
  45. skeletonNode.startListener = ^(spTrackEntry* entry) {
  46. const char* animationName = entry->animation->name;
  47. NSLog(@"%d start: %s", entry->trackIndex, animationName);
  48. };
  49. skeletonNode.interruptListener = ^(spTrackEntry* entry) {
  50. NSLog(@"%d interrupt", entry->trackIndex);
  51. };
  52. skeletonNode.endListener = ^(spTrackEntry* entry) {
  53. NSLog(@"%d end", entry->trackIndex);
  54. };
  55. skeletonNode.disposeListener = ^(spTrackEntry* entry) {
  56. NSLog(@"%d dispose", entry->trackIndex);
  57. };
  58. skeletonNode.completeListener = ^(spTrackEntry* entry) {
  59. NSLog(@"%d complete", entry->trackIndex);
  60. };
  61. skeletonNode.eventListener = ^(spTrackEntry* entry, spEvent* event) {
  62. NSLog(@"%d event: %s, %d, %f, %s", entry->trackIndex, event->data->name, event->intValue, event->floatValue, event->stringValue);
  63. };
  64. [skeletonNode setAnimationForTrack:0 name:@"walk" loop:YES];
  65. [skeletonNode addAnimationForTrack:0 name:@"jump" loop:NO afterDelay:2];
  66. [skeletonNode addAnimationForTrack:0 name:@"run" loop:YES afterDelay:0];
  67. // [skeletonNode setAnimationForTrack:1 name:@"test" loop:YES];
  68. CGSize windowSize = [[CCDirector sharedDirector] viewSize];
  69. [skeletonNode setPosition:ccp(windowSize.width / 2, 20)];
  70. [self addChild:skeletonNode];
  71. self.userInteractionEnabled = YES;
  72. self.contentSize = windowSize;
  73. return self;
  74. }
  75. #if ( TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR )
  76. - (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
  77. if (!skeletonNode.debugBones)
  78. skeletonNode.debugBones = true;
  79. else if (skeletonNode.timeScale == 1)
  80. skeletonNode.timeScale = 0.3f;
  81. else
  82. [[CCDirector sharedDirector] replaceScene:[GoblinsExample scene]];
  83. }
  84. #endif
  85. @end