├── .gitignore ├── AUTHORS ├── Actions ├── Action.h ├── Action.mm ├── ActionInterval.h ├── ActionInterval.mm ├── ActionSequence.h ├── ActionSequence.mm ├── Transitions.h └── Transitions.mm ├── Audio ├── AudioEngine.h └── AudioEngine.mm ├── Bridging Headers ├── cocos-Bridge-Contents.h ├── cocos-Mac-Bridging-Header.h └── cocos-iOS-Bridging-Header.h ├── Events ├── Acceleration.h ├── Acceleration.mm ├── Event.h ├── Event.mm ├── EventDispatcher.h ├── EventDispatcher.mm ├── EventListener.h ├── EventListener.mm ├── EventListenerAcceleration.h ├── EventListenerAcceleration.mm ├── EventListenerKeyboard.h ├── EventListenerKeyboard.mm ├── EventListenerTouch.h ├── EventListenerTouch.mm ├── Touch.h └── Touch.mm ├── Nodes ├── Label.h ├── Label.mm ├── Layer.h ├── Layer.mm ├── Node.h ├── Node.mm ├── Scene.h ├── Scene.mm ├── Sprite.h └── Sprite.mm ├── README.md ├── System ├── Color.h ├── Color.mm ├── Console.h ├── Console.mm ├── Director.h ├── Director.mm ├── Ref.h ├── Ref.mm ├── Utilities.h └── Utilities.mm └── UI ├── Widget.h └── Widget.mm /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore thumbnails created by windows 2 | Thumbs.db 3 | 4 | # Ignore files build by Visual Studio 5 | *.obj 6 | *.exe 7 | *.pdb 8 | *.aps 9 | *.vcproj.*.user 10 | *.vcxproj.user 11 | *.csproj.user 12 | *.vspscc 13 | *_i.c 14 | *.i 15 | *.icf 16 | *_p.c 17 | *.ncb 18 | *.suo 19 | *.tlb 20 | *.tlh 21 | *.bak 22 | *.cache 23 | *.ilk 24 | *.log 25 | [Bb]in 26 | [Dd]ebug/ 27 | [Dd]ebug.win32/ 28 | *.sbr 29 | *.sdf 30 | obj/ 31 | [Rr]elease/ 32 | [Rr]elease.win32/ 33 | _ReSharper*/ 34 | [Tt]est[Rr]esult* 35 | ipch/ 36 | *.opensdf 37 | 38 | # Ignore files build by ndk and eclipse 39 | libs/ 40 | bin/ 41 | obj/ 42 | gen/ 43 | assets/ 44 | local.properties 45 | 46 | # Ignore python compiled files 47 | *.pyc 48 | 49 | # Ignore files build by airplay and marmalade 50 | build_*_xcode/ 51 | build_*_vc10/ 52 | 53 | # Ignore files build by xcode 54 | *.mode*v* 55 | *.pbxuser 56 | *.xcbkptlist 57 | *.xcworkspacedata 58 | *.xcuserstate 59 | *.xccheckout 60 | xcschememanagement.plist 61 | .DS_Store 62 | ._.* 63 | xcuserdata/ 64 | DerivedData/ 65 | 66 | # Ignore files built by AppCode 67 | .idea/ 68 | 69 | # Ignore files built by bada 70 | .Simulator-Debug/ 71 | .Target-Debug/ 72 | .Target-Release/ 73 | 74 | # Ignore files built by blackberry 75 | Simulator/ 76 | Device-Debug/ 77 | Device-Release/ 78 | 79 | # Ignore vim swaps 80 | *.swp 81 | *.swo 82 | 83 | # CTags 84 | tags 85 | 86 | # ignore files, created with make-all-linux-project script 87 | /lib 88 | /build/linux-build 89 | 90 | # Cmake files 91 | CMakeCache.txt 92 | CMakeFiles 93 | Makefile 94 | cmake_install.cmake 95 | 96 | # Android 97 | project.properties 98 | 99 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | Contributors to Swift Bindings to Cocos2d-x 3 | 4 | Justin A. Graham (https://github.com/mannewalis) 5 | 7-2-14 - Added initial implementation to repository. 6 | -------------------------------------------------------------------------------- /Actions/Action.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Action.h 27 | // Created by Justin Graham on 6/26/14. 28 | 29 | #import "Ref.h" 30 | 31 | @interface Action : Ref 32 | - (Action*) clone; 33 | - (Action*) reverse; 34 | - (bool) isDone; 35 | @end 36 | 37 | @interface FiniteTimeAction : Action 38 | @property (nonatomic,assign) float duration; 39 | @end 40 | 41 | -------------------------------------------------------------------------------- /Actions/Action.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Action.mm 27 | // Created by Justin Graham on 6/26/14. 28 | 29 | #import "Action.h" 30 | #include "CCAction.h" 31 | 32 | @implementation Action 33 | 34 | - (Action*) clone 35 | { 36 | INNER(a,Action); 37 | auto r = a->clone(); 38 | SET_OUTER(r, Action); 39 | return GET_OUTER(r,Action); 40 | } 41 | 42 | - (Action*) reverse 43 | { 44 | INNER(a,Action); 45 | auto r = a->reverse(); 46 | SET_OUTER(r, Action); 47 | return GET_OUTER(r,Action); 48 | } 49 | 50 | - (bool) isDone 51 | { 52 | INNER(a,Action); 53 | return a->isDone(); 54 | } 55 | 56 | @end 57 | 58 | @implementation FiniteTimeAction 59 | @end 60 | -------------------------------------------------------------------------------- /Actions/ActionInterval.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // ActionInterval.h 27 | // Created by Justin Graham on 6/26/14. 28 | 29 | #import "Action.h" 30 | 31 | @interface ActionInterval : FiniteTimeAction 32 | @property (nonatomic,readonly) float getElapsed; 33 | @property (nonatomic,readonly) bool firstTick; 34 | - (void) update :(float)t; 35 | @end 36 | 37 | typedef void(^closureActionBlock)(float time); 38 | @interface ClosureAction : ActionInterval 39 | @property (nonatomic,copy) closureActionBlock delegate; 40 | + (ClosureAction*) createWithDuration :(float)duration :(closureActionBlock)delegate; 41 | @end 42 | -------------------------------------------------------------------------------- /Actions/ActionInterval.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // ActionInterval.mm 27 | // Created by Justin Graham on 6/26/14. 28 | 29 | #import "ActionInterval.h" 30 | #include "CCActionInterval.h" 31 | 32 | namespace 33 | { 34 | class _wrap_ActionInterval : public cocos2d::ActionInterval 35 | { 36 | public: 37 | static _wrap_ActionInterval* create(float duration) 38 | { 39 | auto a = new _wrap_ActionInterval; 40 | a->initWithDuration(duration); 41 | return a; 42 | } 43 | _wrap_ActionInterval* reverse() const override 44 | { 45 | return _wrap_ActionInterval::create(-_duration); 46 | } 47 | _wrap_ActionInterval* clone() const override 48 | { 49 | return _wrap_ActionInterval::create(_duration); 50 | } 51 | void update(float t) override 52 | { 53 | ::ActionInterval* a = GET_OUTER(this,::ActionInterval); 54 | [a update:t]; 55 | } 56 | }; 57 | } 58 | 59 | @implementation ActionInterval 60 | - (void) update :(float)t 61 | { 62 | // does nothing 63 | } 64 | @end 65 | 66 | 67 | @implementation ClosureAction 68 | + (ClosureAction*) createWithDuration :(float)duration :(closureActionBlock)delegate 69 | { 70 | auto a = [[ClosureAction alloc] init]; 71 | a.inner = _wrap_ActionInterval::create(duration); 72 | a.delegate = delegate; 73 | return a; 74 | } 75 | 76 | - (void) update :(float)t 77 | { 78 | if (self.delegate) 79 | self.delegate(t); 80 | } 81 | @end 82 | -------------------------------------------------------------------------------- /Actions/ActionSequence.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // ActionSequence.h 27 | // Created by Justin Graham on 6/29/14. 28 | 29 | #import "ActionInterval.h" 30 | 31 | @interface ActionSequence : ActionInterval 32 | + (ActionSequence*) create :(NSArray*)actions; 33 | @end 34 | -------------------------------------------------------------------------------- /Actions/ActionSequence.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // ActionSequence.m 27 | // Created by Justin Graham on 6/29/14. 28 | 29 | #import "ActionSequence.h" 30 | #include "CCVector.h" 31 | #include "CCAction.h" 32 | #include "CCActionInterval.h" 33 | 34 | @implementation ActionSequence 35 | + (ActionSequence*) create :(NSArray*)actions 36 | { 37 | cocos2d::Vector arrayOfActions; 38 | for (Action* action in actions) 39 | { 40 | [action retain]; // match inner retain below 41 | arrayOfActions.pushBack(static_cast(action.inner)); 42 | } 43 | ActionSequence* sequence = [ActionSequence new]; 44 | sequence.inner = cocos2d::Sequence::create(arrayOfActions); 45 | return sequence; 46 | } 47 | @end 48 | -------------------------------------------------------------------------------- /Actions/Transitions.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Transitions.h 27 | // Created by Justin Graham on 6/27/14. 28 | 29 | #import "Scene.h" 30 | 31 | @interface TransitionScene : Scene 32 | + (TransitionScene*) create :(float)duration :(Scene*)scene; 33 | @end 34 | 35 | @interface TransitionFade : TransitionScene 36 | + (TransitionFade*) create :(float)duration :(Scene*)scene; 37 | @end -------------------------------------------------------------------------------- /Actions/Transitions.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Transitions.m 27 | // Created by Justin Graham on 6/27/14. 28 | 29 | #import "Transitions.h" 30 | #include "CCTransition.h" 31 | 32 | @implementation TransitionScene 33 | + (TransitionScene*) create :(float)duration :(Scene*)scene 34 | { 35 | [scene retain]; 36 | TransitionScene* transition = [TransitionScene new]; 37 | transition.inner = cocos2d::TransitionScene::create(duration, static_cast(scene.inner)); 38 | return [transition autorelease]; 39 | } 40 | @end 41 | 42 | @implementation TransitionFade 43 | + (TransitionFade*) create :(float)duration :(Scene*)scene 44 | { 45 | [scene retain]; 46 | TransitionFade* transition = [TransitionFade new]; 47 | transition.inner = cocos2d::TransitionFade::create(duration, static_cast(scene.inner)); 48 | return [transition autorelease]; 49 | } 50 | @end 51 | -------------------------------------------------------------------------------- /Audio/AudioEngine.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // AudioEngine.h 27 | // Created by Justin Graham on 7/3/14. 28 | 29 | #import "Ref.h" 30 | #include "stdint.h" 31 | 32 | @interface AudioEngine : Ref 33 | + (AudioEngine*) getInstance; 34 | - (void) preloadBackgroundMusic :(NSString*)path; 35 | - (void) playBackgroundMusic :(NSString*)path :(bool)loop; 36 | - (void) stopBackgroundMusic; 37 | - (void) pauseBackgroundMusic; 38 | - (void) resumeBackgroundMusic; 39 | - (void) rewindBackgroundMusic; 40 | - (bool) isBackgroundMusicPlaying; 41 | - (void) setBackgroundMusicVolume :(float)volume; 42 | - (float) getEffectsVolume; 43 | - (void) setEffectsVolume :(float)volume; 44 | - (uint32_t) playEffect :(NSString*)path :(bool)loop :(float)pan :(float)gain; 45 | - (void) pauseEffect :(uint32_t)id; 46 | - (void) pauseAllEffects; 47 | - (void) resumeEffect :(uint32_t)id; 48 | - (void) resumeAllEffects; 49 | - (void) stopEffect :(uint32_t)id; 50 | - (void) stopAllEffects; 51 | - (void) preloadEffect :(NSString*)path; 52 | - (void) unloadEffect :(NSString*)path; 53 | @end 54 | -------------------------------------------------------------------------------- /Audio/AudioEngine.mm: -------------------------------------------------------------------------------- 1 | // 2 | // AudioEngine.m 3 | // swiftress 4 | // 5 | // Created by Justin Graham on 7/3/14. 6 | // 7 | // 8 | 9 | #import "AudioEngine.h" 10 | #include "SimpleAudioEngine.h" 11 | 12 | @implementation AudioEngine 13 | + (AudioEngine*) getInstance 14 | { 15 | static AudioEngine* instance = nil; 16 | static dispatch_once_t onceToken; 17 | dispatch_once(&onceToken, ^{ 18 | instance = [[self alloc] init]; 19 | instance.inner = CocosDenshion::SimpleAudioEngine::getInstance(); 20 | }); 21 | return instance; 22 | } 23 | 24 | - (void) preloadBackgroundMusic :(NSString*)path 25 | { 26 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 27 | ae->preloadBackgroundMusic([path UTF8String]); 28 | } 29 | 30 | - (void) playBackgroundMusic :(NSString*)path :(bool)loop 31 | { 32 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 33 | ae->playBackgroundMusic([path UTF8String], loop); 34 | } 35 | 36 | - (void) stopBackgroundMusic 37 | { 38 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 39 | ae->stopBackgroundMusic(); 40 | } 41 | 42 | - (void) pauseBackgroundMusic 43 | { 44 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 45 | ae->pauseBackgroundMusic(); 46 | } 47 | 48 | - (void) resumeBackgroundMusic 49 | { 50 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 51 | ae->resumeBackgroundMusic(); 52 | } 53 | 54 | - (void) rewindBackgroundMusic 55 | { 56 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 57 | ae->rewindBackgroundMusic(); 58 | } 59 | 60 | - (bool) isBackgroundMusicPlaying 61 | { 62 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 63 | return ae->isBackgroundMusicPlaying(); 64 | } 65 | 66 | - (void) setBackgroundMusicVolume :(float)volume 67 | { 68 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 69 | ae->setBackgroundMusicVolume(volume); 70 | } 71 | 72 | - (float) getEffectsVolume 73 | { 74 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 75 | return ae->getEffectsVolume(); 76 | } 77 | 78 | - (void) setEffectsVolume :(float)volume 79 | { 80 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 81 | ae->setEffectsVolume(volume); 82 | } 83 | 84 | - (uint32_t) playEffect :(NSString*)path :(bool)loop :(float)pan :(float)gain 85 | { 86 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 87 | return ae->playEffect([path UTF8String], loop, pan, gain); 88 | } 89 | 90 | - (void) pauseEffect :(uint32_t)id 91 | { 92 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 93 | ae->pauseEffect(id); 94 | } 95 | 96 | - (void) pauseAllEffects 97 | { 98 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 99 | ae->pauseAllEffects(); 100 | } 101 | 102 | - (void) resumeEffect :(uint32_t)id 103 | { 104 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 105 | ae->resumeEffect(id); 106 | } 107 | 108 | - (void) resumeAllEffects 109 | { 110 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 111 | ae->resumeAllEffects(); 112 | } 113 | 114 | - (void) stopEffect :(uint32_t)id 115 | { 116 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 117 | ae->stopEffect(id); 118 | } 119 | 120 | - (void) stopAllEffects 121 | { 122 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 123 | ae->stopAllEffects(); 124 | } 125 | 126 | - (void) preloadEffect :(NSString*)path 127 | { 128 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 129 | ae->preloadEffect([path UTF8String]); 130 | } 131 | 132 | - (void) unloadEffect :(NSString*)path 133 | { 134 | INNERNS(ae,CocosDenshion::SimpleAudioEngine); 135 | ae->unloadEffect([path UTF8String]); 136 | } 137 | @end 138 | -------------------------------------------------------------------------------- /Bridging Headers/cocos-Bridge-Contents.h: -------------------------------------------------------------------------------- 1 | 2 | // swiftress Bridge-Contents.h 3 | // Created by Justin Graham on 6/20/14. 4 | 5 | #import "Acceleration.h" 6 | #import "Action.h" 7 | #import "ActionInterval.h" 8 | #import "ActionSequence.h" 9 | #import "AudioEngine.h" 10 | #import "Color.h" 11 | #import "Console.h" 12 | #import "Director.h" 13 | #import "Event.h" 14 | #import "EventDispatcher.h" 15 | #import "EventListener.h" 16 | #import "EventListenerAcceleration.h" 17 | #import "EventListenerKeyboard.h" 18 | #import "EventListenerTouch.h" 19 | #import "Label.h" 20 | #import "Node.h" 21 | #import "Ref.h" 22 | #import "Scene.h" 23 | #import "Sprite.h" 24 | #import "Touch.h" 25 | #import "Transitions.h" 26 | #import "Utilities.h" 27 | -------------------------------------------------------------------------------- /Bridging Headers/cocos-Mac-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | #include "cocos-Bridge-Contents.h" -------------------------------------------------------------------------------- /Bridging Headers/cocos-iOS-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | #include "cocos-Bridge-Contents.h" -------------------------------------------------------------------------------- /Events/Acceleration.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Acceleration.h 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "Ref.h" 30 | 31 | @interface Acceleration : Ref 32 | @property (nonatomic) double x; 33 | @property (nonatomic) double y; 34 | @property (nonatomic) double z; 35 | @property (nonatomic) double timestamp; 36 | @end 37 | -------------------------------------------------------------------------------- /Events/Acceleration.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Acceleration.mm 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "Acceleration.h" 30 | 31 | @implementation Acceleration 32 | @end 33 | -------------------------------------------------------------------------------- /Events/Event.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Event.h 27 | // Created by Justin Graham on 6/22/14. 28 | 29 | #import "Ref.h" 30 | 31 | @class Node; 32 | 33 | @interface Event : Ref 34 | - (int) getType; 35 | - (void) stopPropagation; 36 | - (bool) isStopped; 37 | - (Node*) getCurrentTarget; 38 | @end 39 | -------------------------------------------------------------------------------- /Events/Event.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Event.mm 27 | // Created by Justin Graham on 6/22/14. 28 | 29 | #import "Event.h" 30 | #import "Node.h" 31 | #include "CCEvent.h" 32 | #include "CCNode.h" 33 | 34 | @implementation Event 35 | - (int) getType 36 | { 37 | INNER(e,Event); 38 | return static_cast(e->getType()); 39 | } 40 | 41 | - (void) stopPropagation 42 | { 43 | INNER(e,Event); 44 | e->stopPropagation(); 45 | } 46 | 47 | - (bool) isStopped 48 | { 49 | INNER(e,Event); 50 | return e->isStopped(); 51 | } 52 | 53 | - (Node*) getCurrentTarget 54 | { 55 | INNER(e,Event); 56 | auto n = e->getCurrentTarget(); 57 | return GET_OUTER(n, Node); 58 | } 59 | @end 60 | -------------------------------------------------------------------------------- /Events/EventDispatcher.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventDispatcher.h 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "Ref.h" 30 | 31 | @class EventListener; 32 | @class Node; 33 | @class Event; 34 | 35 | @interface EventDispatcher : Ref 36 | - (void) addEventListenerWithSceneGraphPriority :(EventListener*)listener :(Node*)node; 37 | - (void) removeEventListener :(EventListener*)listener; 38 | - (void) removeEventListenersForTarget :(Node*)target :(bool)recursive; 39 | - (void) dispatchEvent :(Event*)event; 40 | @end 41 | -------------------------------------------------------------------------------- /Events/EventDispatcher.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventDispatcher.mm 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "EventDispatcher.h" 30 | #import "Event.h" 31 | #import "EventListener.h" 32 | #import "Node.h" 33 | #include "CCDirector.h" 34 | #include "CCEventDispatcher.h" 35 | #include "CCEvent.h" 36 | #include "CCNode.h" 37 | 38 | @implementation EventDispatcher 39 | - (id) init 40 | { 41 | self.inner = cocos2d::Director::getInstance()->getEventDispatcher(); 42 | return self; 43 | } 44 | 45 | - (void) addEventListenerWithSceneGraphPriority :(EventListener*)listener :(Node*)node 46 | { 47 | INNER(d,EventDispatcher); 48 | [listener retain]; 49 | d->addEventListenerWithSceneGraphPriority(static_cast(listener.inner), static_cast(node.inner)); 50 | } 51 | 52 | - (void) removeEventListener :(EventListener*) listener 53 | { 54 | INNER(d,EventDispatcher); 55 | d->removeEventListener(static_cast(listener.inner)); 56 | [listener release]; 57 | } 58 | 59 | - (void) removeEventListenersForTarget :(Node*)target :(bool)recursive 60 | { 61 | INNER(d,EventDispatcher); 62 | d->removeEventListenersForTarget(static_cast(target.inner), recursive); 63 | } 64 | 65 | - (void) dispatchEvent :(Event*) event 66 | { 67 | INNER(d,EventDispatcher); 68 | d->dispatchEvent(static_cast(event.inner)); 69 | } 70 | @end 71 | -------------------------------------------------------------------------------- /Events/EventListener.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListener.h 27 | // Created by Justin Graham on 6/22/14. 28 | 29 | #import "Ref.h" 30 | 31 | @interface EventListener : Ref 32 | @property (nonatomic) bool enabled; 33 | @end 34 | -------------------------------------------------------------------------------- /Events/EventListener.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListener.mm 27 | // Created by Justin Graham on 6/22/14. 28 | 29 | #import "EventListener.h" 30 | #import "Event.h" 31 | #include "CCEventListener.h" 32 | 33 | @implementation EventListener 34 | typedef void(^callback)(Event*); 35 | - (void) setEnabled:(bool)enabled 36 | { 37 | INNER(l, EventListener); 38 | l->setEnabled(enabled); 39 | } 40 | 41 | - (bool) enabled 42 | { 43 | INNER(l, EventListener); 44 | return l->isEnabled(); 45 | } 46 | @end 47 | -------------------------------------------------------------------------------- /Events/EventListenerAcceleration.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListenerAcceleration.h 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "EventListener.h" 30 | 31 | @class Acceleration; 32 | @class Event; 33 | 34 | typedef void(^AccelerationCallback)(Acceleration*, Event*); 35 | 36 | @interface EventListenerAcceleration : EventListener 37 | @property (nonatomic,readonly) NSString* LISTENER_ID; 38 | @property (nonatomic,copy) AccelerationCallback onAccelerate; 39 | + (EventListenerAcceleration*) create :(AccelerationCallback)callback; 40 | - (EventListenerAcceleration*) clone; 41 | - (bool) checkAvailable; 42 | @end 43 | -------------------------------------------------------------------------------- /Events/EventListenerAcceleration.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListenerAcceleration.mm 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "EventListenerAcceleration.h" 30 | #import "Acceleration.h" 31 | #import "Event.h" 32 | #include "CCEventListenerAcceleration.h" 33 | #include "CCEvent.h" 34 | 35 | @interface EventListenerAcceleration() 36 | @property (nonatomic,copy) NSString* LISTENER_ID; 37 | @end 38 | 39 | @implementation EventListenerAcceleration 40 | @synthesize LISTENER_ID; 41 | + (EventListenerAcceleration*) create :(AccelerationCallback)callback 42 | { 43 | auto el = [EventListenerAcceleration new]; 44 | el.onAccelerate = callback; 45 | el.inner = cocos2d::EventListenerAcceleration::create([el](cocos2d::Acceleration* a, cocos2d::Event* e) 46 | { 47 | SET_OUTER(a, Acceleration); 48 | SET_OUTER(e, Event); 49 | auto aa = GET_OUTER(a, Acceleration); 50 | auto ee = GET_OUTER(e, Event); 51 | if (el.onAccelerate) 52 | el.onAccelerate(aa, ee); 53 | }); 54 | return el; 55 | } 56 | 57 | - (EventListenerAcceleration*) clone 58 | { 59 | return [EventListenerAcceleration create:self.onAccelerate]; 60 | } 61 | 62 | - (bool) checkAvailable 63 | { 64 | INNER(e, EventListenerAcceleration); 65 | return e->checkAvailable(); 66 | } 67 | @end 68 | -------------------------------------------------------------------------------- /Events/EventListenerKeyboard.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListenerKeyboard.h 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "EventListener.h" 30 | 31 | @class Event; 32 | 33 | @interface EventListenerKeyboard : EventListener 34 | typedef NS_ENUM(NSInteger, KeyCode) 35 | { 36 | KeyCodeNONE, 37 | KeyCodePAUSE, 38 | KeyCodeSCROLL_LOCK, 39 | KeyCodePRINT, 40 | KeyCodeSYSREQ, 41 | KeyCodeBREAK, 42 | KeyCodeESCAPE, 43 | KeyCodeBACKSPACE, 44 | KeyCodeTAB, 45 | KeyCodeBACK_TAB, 46 | KeyCodeRETURN, 47 | KeyCodeCAPS_LOCK, 48 | KeyCodeSHIFT, 49 | KeyCodeCTRL, 50 | KeyCodeALT, 51 | KeyCodeMENU, 52 | KeyCodeHYPER, 53 | KeyCodeINSERT, 54 | KeyCodeHOME, 55 | KeyCodePG_UP, 56 | KeyCodeDELETE, 57 | KeyCodeEND, 58 | KeyCodePG_DOWN, 59 | KeyCodeLEFT_ARROW, 60 | KeyCodeRIGHT_ARROW, 61 | KeyCodeUP_ARROW, 62 | KeyCodeDOWN_ARROW, 63 | KeyCodeNUM_LOCK, 64 | KeyCodeKP_PLUS, 65 | KeyCodeKP_MINUS, 66 | KeyCodeKP_MULTIPLY, 67 | KeyCodeKP_DIVIDE, 68 | KeyCodeKP_ENTER, 69 | KeyCodeKP_HOME, 70 | KeyCodeKP_UP, 71 | KeyCodeKP_PG_UP, 72 | KeyCodeKP_LEFT, 73 | KeyCodeKP_FIVE, 74 | KeyCodeKP_RIGHT, 75 | KeyCodeKP_END, 76 | KeyCodeKP_DOWN, 77 | KeyCodeKP_PG_DOWN, 78 | KeyCodeKP_INSERT, 79 | KeyCodeKP_DELETE, 80 | KeyCodeF1, 81 | KeyCodeF2, 82 | KeyCodeF3, 83 | KeyCodeF4, 84 | KeyCodeF5, 85 | KeyCodeF6, 86 | KeyCodeF7, 87 | KeyCodeF8, 88 | KeyCodeF9, 89 | KeyCodeF10, 90 | KeyCodeF11, 91 | KeyCodeF12, 92 | KeyCodeSPACE, 93 | KeyCodeEXCLAM, 94 | KeyCodeQUOTE, 95 | KeyCodeNUMBER, 96 | KeyCodeDOLLAR, 97 | KeyCodePERCENT, 98 | KeyCodeCIRCUMFLEX, 99 | KeyCodeAMPERSAND, 100 | KeyCodeAPOSTROPHE, 101 | KeyCodeLEFT_PARENTHESIS, 102 | KeyCodeRIGHT_PARENTHESIS, 103 | KeyCodeASTERISK, 104 | KeyCodePLUS, 105 | KeyCodeCOMMA, 106 | KeyCodeMINUS, 107 | KeyCodePERIOD, 108 | KeyCodeSLASH, 109 | KeyCode0, 110 | KeyCode1, 111 | KeyCode2, 112 | KeyCode3, 113 | KeyCode4, 114 | KeyCode5, 115 | KeyCode6, 116 | KeyCode7, 117 | KeyCode8, 118 | KeyCode9, 119 | KeyCodeCOLON, 120 | KeyCodeSEMICOLON, 121 | KeyCodeLESS_THAN, 122 | KeyCodeEQUAL, 123 | KeyCodeGREATER_THAN, 124 | KeyCodeQUESTION, 125 | KeyCodeAT, 126 | KeyCodeCAPITAL_A, 127 | KeyCodeCAPITAL_B, 128 | KeyCodeCAPITAL_C, 129 | KeyCodeCAPITAL_D, 130 | KeyCodeCAPITAL_E, 131 | KeyCodeCAPITAL_F, 132 | KeyCodeCAPITAL_G, 133 | KeyCodeCAPITAL_H, 134 | KeyCodeCAPITAL_I, 135 | KeyCodeCAPITAL_J, 136 | KeyCodeCAPITAL_K, 137 | KeyCodeCAPITAL_L, 138 | KeyCodeCAPITAL_M, 139 | KeyCodeCAPITAL_N, 140 | KeyCodeCAPITAL_O, 141 | KeyCodeCAPITAL_P, 142 | KeyCodeCAPITAL_Q, 143 | KeyCodeCAPITAL_R, 144 | KeyCodeCAPITAL_S, 145 | KeyCodeCAPITAL_T, 146 | KeyCodeCAPITAL_U, 147 | KeyCodeCAPITAL_V, 148 | KeyCodeCAPITAL_W, 149 | KeyCodeCAPITAL_X, 150 | KeyCodeCAPITAL_Y, 151 | KeyCodeCAPITAL_Z, 152 | KeyCodeLEFT_BRACKET, 153 | KeyCodeBACK_SLASH, 154 | KeyCodeRIGHT_BRACKET, 155 | KeyCodeUNDERSCORE, 156 | KeyCodeGRAVE, 157 | KeyCodeA, 158 | KeyCodeB, 159 | KeyCodeC, 160 | KeyCodeD, 161 | KeyCodeE, 162 | KeyCodeF, 163 | KeyCodeG, 164 | KeyCodeH, 165 | KeyCodeI, 166 | KeyCodeJ, 167 | KeyCodeK, 168 | KeyCodeL, 169 | KeyCodeM, 170 | KeyCodeN, 171 | KeyCodeO, 172 | KeyCodeP, 173 | KeyCodeQ, 174 | KeyCodeR, 175 | KeyCodeS, 176 | KeyCodeT, 177 | KeyCodeU, 178 | KeyCodeV, 179 | KeyCodeW, 180 | KeyCodeX, 181 | KeyCodeY, 182 | KeyCodeZ, 183 | KeyCodeLEFT_BRACE, 184 | KeyCodeBAR, 185 | KeyCodeRIGHT_BRACE, 186 | KeyCodeTILDE, 187 | KeyCodeEURO, 188 | KeyCodePOUND, 189 | KeyCodeYEN, 190 | KeyCodeMIDDLE_DOT, 191 | KeyCodeSEARCH, 192 | KeyCodeDPAD_LEFT, 193 | KeyCodeDPAD_RIGHT, 194 | KeyCodeDPAD_UP, 195 | KeyCodeDPAD_DOWN, 196 | KeyCodeDPAD_CENTER, 197 | KeyCodeENTER, 198 | KeyCodePLAY, 199 | }; 200 | 201 | typedef void(^voidKeyBlock)(KeyCode, Event*); 202 | 203 | @property (nonatomic,copy) voidKeyBlock onKeyPressed; 204 | @property (nonatomic,copy) voidKeyBlock onKeyReleased; 205 | 206 | - (id) init; 207 | + (EventListenerKeyboard*) create; 208 | - (bool) checkAvailable; 209 | - (EventListenerKeyboard*) clone; 210 | @end 211 | 212 | -------------------------------------------------------------------------------- /Events/EventListenerKeyboard.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListenerKeyboard.mm 27 | // Created by Justin Graham on 6/30/14. 28 | 29 | #import "EventListenerKeyboard.h" 30 | #import "Event.h" 31 | #include "CCEventListenerKeyboard.h" 32 | 33 | @implementation EventListenerKeyboard 34 | - (id) init 35 | { 36 | self.inner = cocos2d::EventListenerKeyboard::create(); 37 | INNER(e,EventListenerKeyboard); 38 | 39 | e->onKeyPressed = [self](cocos2d::EventKeyboard::KeyCode kc, cocos2d::Event* event) 40 | { 41 | SET_OUTER(event, Event); 42 | auto e = GET_OUTER(event, Event); 43 | if (self.onKeyPressed) 44 | self.onKeyPressed(KeyCode(kc), e); 45 | }; 46 | 47 | e->onKeyReleased = [self](cocos2d::EventKeyboard::KeyCode kc, cocos2d::Event* event) 48 | { 49 | SET_OUTER(event, Event); 50 | auto e = GET_OUTER(event, Event); 51 | if (self.onKeyReleased) 52 | self.onKeyReleased(KeyCode(kc), e); 53 | }; 54 | 55 | return self; 56 | } 57 | 58 | + (EventListenerKeyboard*) create 59 | { 60 | EventListenerKeyboard* listener = [EventListenerKeyboard alloc]; 61 | [listener autorelease]; 62 | return nil == [listener init] ? nil : listener; 63 | } 64 | 65 | - (bool) checkAvailable 66 | { 67 | return nil != self.onKeyPressed || nil != self.onKeyReleased; 68 | } 69 | 70 | - (EventListenerKeyboard*) clone 71 | { 72 | EventListenerKeyboard* listener = [EventListenerKeyboard create]; 73 | if (listener) 74 | { 75 | listener.onKeyPressed = self.onKeyPressed; 76 | listener.onKeyReleased = self.onKeyReleased; 77 | } 78 | return listener; 79 | } 80 | @end 81 | -------------------------------------------------------------------------------- /Events/EventListenerTouch.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListenerTouch.h 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "EventListener.h" 30 | 31 | @class Touch; 32 | @class Event; 33 | 34 | @interface EventListenerTouchOneByOne : EventListener 35 | typedef bool(^boolBlock)(Touch*, Event*); 36 | typedef void(^voidBlock)(Touch*, Event*); 37 | @property (nonatomic,copy) boolBlock onTouchBegan; 38 | @property (nonatomic,copy) voidBlock onTouchMoved; 39 | @property (nonatomic,copy) voidBlock onTouchEnded; 40 | @property (nonatomic,copy) voidBlock onTouchCancelled; 41 | @property (nonatomic,retain) NSArray* claimedTouches; 42 | @property (nonatomic) bool swallowTouches; 43 | @property (nonatomic) bool needSwallow; 44 | - (id) init; 45 | + (EventListenerTouchOneByOne*) create; 46 | - (bool) checkAvailable; 47 | - (EventListenerTouchOneByOne*) clone; 48 | @end 49 | 50 | -------------------------------------------------------------------------------- /Events/EventListenerTouch.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // EventListenerTouchOneByOne.mm 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "EventListenerTouch.h" 30 | #import "Event.h" 31 | #import "Touch.h" 32 | #include "CCEventListenerTouch.h" 33 | #include "CCTouch.h" 34 | #include "CCEvent.h" 35 | 36 | @implementation EventListenerTouchOneByOne 37 | - (id) init 38 | { 39 | self.inner = cocos2d::EventListenerTouchOneByOne::create(); 40 | INNER(e,EventListenerTouchOneByOne); 41 | e->onTouchBegan = [self](cocos2d::Touch* touch, cocos2d::Event* event) 42 | { 43 | SET_OUTER(touch, Touch); 44 | SET_OUTER(event, Event); 45 | auto t = GET_OUTER(touch, Touch); 46 | auto e = GET_OUTER(event, Event); 47 | return self.onTouchBegan ? self.onTouchBegan(t, e) : true; 48 | }; 49 | 50 | e->onTouchMoved = [self](cocos2d::Touch* touch, cocos2d::Event* event) 51 | { 52 | SET_OUTER(touch, Touch); 53 | SET_OUTER(event, Event); 54 | auto t = GET_OUTER(touch, Touch); 55 | auto e = GET_OUTER(event, Event); 56 | if (self.onTouchMoved) 57 | self.onTouchMoved(t, e); 58 | }; 59 | 60 | e->onTouchEnded = [self](cocos2d::Touch* touch, cocos2d::Event* event) 61 | { 62 | SET_OUTER(touch, Touch); 63 | SET_OUTER(event, Event); 64 | auto t = GET_OUTER(touch, Touch); 65 | auto e = GET_OUTER(event, Event); 66 | if (self.onTouchEnded) 67 | self.onTouchEnded(t, e); 68 | }; 69 | 70 | e->onTouchCancelled = [self](cocos2d::Touch* touch, cocos2d::Event* event) 71 | { 72 | SET_OUTER(touch, Touch); 73 | SET_OUTER(event, Event); 74 | auto t = GET_OUTER(touch, Touch); 75 | auto e = GET_OUTER(event, Event); 76 | if (self.onTouchCancelled) 77 | self.onTouchCancelled(t, e); 78 | }; 79 | 80 | return self; 81 | } 82 | 83 | + (EventListenerTouchOneByOne*) create 84 | { 85 | EventListenerTouchOneByOne* listener = [EventListenerTouchOneByOne alloc]; 86 | [listener autorelease]; 87 | return nil == [listener init] ? nil : listener; 88 | } 89 | 90 | - (bool) checkAvailable 91 | { 92 | return nil != self.onTouchBegan; 93 | } 94 | 95 | - (EventListenerTouchOneByOne*) clone 96 | { 97 | EventListenerTouchOneByOne* listener = [EventListenerTouchOneByOne create]; 98 | if (listener) 99 | { 100 | listener.onTouchBegan = self.onTouchBegan; 101 | listener.onTouchMoved = self.onTouchMoved; 102 | listener.onTouchEnded = self.onTouchEnded; 103 | listener.onTouchCancelled = self.onTouchCancelled; 104 | listener.needSwallow = self.needSwallow; 105 | listener.claimedTouches = [NSArray arrayWithArray:self.claimedTouches]; 106 | } 107 | return listener; 108 | } 109 | @end 110 | -------------------------------------------------------------------------------- /Events/Touch.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Touch.h 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "Ref.h" 30 | 31 | @interface Touch : Ref 32 | - (CGPoint) getLocation; 33 | - (CGPoint) getPreviousLocation; 34 | - (CGPoint) getStartLocation; 35 | - (CGPoint) getDelta; 36 | - (CGPoint) getLocationInView; 37 | - (CGPoint) getPreviousLocationInView; 38 | - (CGPoint) getStartLocationInView; 39 | - (void) setTouchInfo :(int)id :(float)x :(float)y; 40 | - (int) getID; 41 | @end 42 | -------------------------------------------------------------------------------- /Events/Touch.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Touch.m 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "Touch.h" 30 | #include "CCTouch.h" 31 | 32 | @implementation Touch 33 | - (CGPoint) getLocation 34 | { 35 | INNER(t,Touch); 36 | auto v = t->getLocation(); 37 | return CGPointMake(v.x, v.y); 38 | } 39 | 40 | - (CGPoint) getPreviousLocation 41 | { 42 | INNER(t,Touch); 43 | auto v = t->getPreviousLocation(); 44 | return CGPointMake(v.x, v.y); 45 | } 46 | 47 | - (CGPoint) getStartLocation 48 | { 49 | INNER(t,Touch); 50 | auto v = t->getStartLocation(); 51 | return CGPointMake(v.x, v.y); 52 | } 53 | 54 | - (CGPoint) getDelta 55 | { 56 | INNER(t,Touch); 57 | auto v = t->getDelta(); 58 | return CGPointMake(v.x, v.y); 59 | } 60 | 61 | - (CGPoint) getLocationInView 62 | { 63 | INNER(t,Touch); 64 | auto v = t->getLocationInView(); 65 | return CGPointMake(v.x, v.y); 66 | } 67 | 68 | - (CGPoint) getPreviousLocationInView 69 | { 70 | INNER(t,Touch); 71 | auto v = t->getPreviousLocationInView(); 72 | return CGPointMake(v.x, v.y); 73 | } 74 | 75 | - (CGPoint) getStartLocationInView 76 | { 77 | INNER(t,Touch); 78 | auto v = t->getStartLocationInView(); 79 | return CGPointMake(v.x, v.y); 80 | } 81 | 82 | - (void) setTouchInfo :(int)id :(float)x :(float)y 83 | { 84 | INNER(t,Touch); 85 | t->setTouchInfo(id, x, y); 86 | } 87 | 88 | - (int) getID 89 | { 90 | INNER(t,Touch); 91 | return t->getID(); 92 | } 93 | @end 94 | -------------------------------------------------------------------------------- /Nodes/Label.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Label.h 27 | // Created by Justin Graham on 6/25/14. 28 | 29 | #import "Node.h" 30 | #import "Color.h" 31 | 32 | @interface Label : Node 33 | + (Label*) create; 34 | + (Label*) createWithSystemFont :(NSString*)text :(NSString*)font :(float)fontSize; 35 | + (Label*) createWithTTF :(NSString*)text :(NSString*)fontFile :(float)fontSize; 36 | - (void) setString :(NSString*)text; 37 | - (void) setTextColor :(Color4B*)color; 38 | - (void) enableShadow :(Color4B*)color :(CGSize)offset :(int)blurRadius; 39 | - (void) enableOutline :(Color4B*)outlineColor :(int)outlineSize; 40 | - (void) enableGlow :(Color4B*)glowColor; 41 | - (void) disableEffect; 42 | @end 43 | -------------------------------------------------------------------------------- /Nodes/Label.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Label.mm 27 | // Created by Justin Graham on 6/25/14. 28 | 29 | #import "Label.h" 30 | #include "CCLabel.h" 31 | 32 | @implementation Label 33 | 34 | + (Label*) create 35 | { 36 | auto label = [Label alloc]; 37 | label.inner = cocos2d::Label::create(); 38 | return [label autorelease]; 39 | } 40 | 41 | + (Label*) createWithSystemFont :(NSString*)text :(NSString*)font :(float)fontSize 42 | { 43 | auto label = [Label alloc]; 44 | label.inner = cocos2d::Label::createWithSystemFont([text UTF8String], [font UTF8String], fontSize); 45 | return [label autorelease]; 46 | } 47 | 48 | + (Label*) createWithTTF :(NSString*)text :(NSString*)fontFile :(float)fontSize 49 | { 50 | auto label = [Label alloc]; 51 | label.inner = cocos2d::Label::createWithTTF([text UTF8String], [fontFile UTF8String], fontSize); 52 | return [label autorelease]; 53 | } 54 | 55 | - (id) init 56 | { 57 | [self initCommon]; 58 | return self; 59 | } 60 | 61 | - (void) setString :(NSString*)text 62 | { 63 | INNER(l,Label); 64 | l->setString([text UTF8String]); 65 | } 66 | 67 | - (void) setTextColor :(Color4B*)color 68 | { 69 | INNER(l,Label); 70 | cocos2d::Color4B c(color.r, color.g, color.b, color.a); 71 | l->setTextColor(c); 72 | } 73 | 74 | - (void) enableShadow :(Color4B*)color :(CGSize)offset :(int)blurRadius 75 | { 76 | INNER(l,Label); 77 | cocos2d::Color4B c(color.r, color.g, color.b, color.a); 78 | l->enableShadow(c, cocos2d::Size(offset.width, offset.height), blurRadius); 79 | } 80 | 81 | - (void) enableOutline :(Color4B*)outlineColor :(int)outlineSize 82 | { 83 | INNER(l,Label); 84 | cocos2d::Color4B c(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a); 85 | l->enableOutline(c, outlineSize); 86 | } 87 | 88 | - (void) enableGlow :(Color4B*)glowColor 89 | { 90 | INNER(l,Label); 91 | cocos2d::Color4B c(glowColor.r, glowColor.g, glowColor.b, glowColor.a); 92 | l->enableGlow(c); 93 | } 94 | 95 | - (void) disableEffect 96 | { 97 | INNER(l,Label); 98 | l->disableEffect(); 99 | } 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /Nodes/Layer.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Layer.h 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "Node.h" 30 | 31 | @interface Layer : Node 32 | @end 33 | -------------------------------------------------------------------------------- /Nodes/Layer.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Layer.m 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "Layer.h" 30 | 31 | @implementation Layer 32 | @end 33 | -------------------------------------------------------------------------------- /Nodes/Node.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Node.h 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Ref.h" 30 | 31 | @class Action; 32 | 33 | typedef void(^tUpdateBlock)(float); 34 | 35 | @interface Node : Ref 36 | { 37 | @protected 38 | tUpdateBlock _update; 39 | NSMutableArray* _children; 40 | } 41 | 42 | + (Node*) create; 43 | 44 | - (void) initCommon; 45 | 46 | - (void) setAnchorPoint :(CGPoint)anchor; 47 | - (CGPoint) getAnchorPoint; 48 | 49 | - (void) setPosition :(CGPoint)pos; 50 | - (void) setPosition :(float)x :(float)y; 51 | - (CGPoint) getPosition; 52 | 53 | - (float) getRotation; 54 | - (void) setRotation :(float)r; 55 | 56 | - (void) setOpacity :(float)a; 57 | - (float) getOpacity; 58 | 59 | - (void) setScaleX :(float)scaleX; 60 | - (void) setScaleY :(float)scaleY; 61 | - (void) setScaleZ :(float)scaleZ; 62 | - (float) getScaleX; 63 | - (float) getScaleY; 64 | - (float) getScaleZ; 65 | - (void) setScale :(float)scale; 66 | - (float) getScale; 67 | - (void) setScale :(float)scaleX :(float)scaleY; 68 | 69 | - (void) addChild :(Node*)child; 70 | - (void) removeChild :(Node*)child; 71 | - (NSArray*) getChildren; 72 | - (Node*) getParent; 73 | - (void) removeAllChildren; 74 | 75 | - (CGSize) getContentSize; 76 | - (void) setContentSize :(CGSize)size; 77 | 78 | - (void) scheduleUpdate :(tUpdateBlock)update; 79 | - (void) unscheduleUpdate; 80 | 81 | - (CGPoint) convertToNodeSpace :(CGPoint)worldPoint; 82 | - (CGPoint) convertToWorldSpace :(CGPoint)nodePoint; 83 | 84 | - (Action*) runAction :(Action*)action; 85 | - (void) stopAction :(Action*)action; 86 | - (void) stopAllActions; 87 | 88 | - (void) onEnter; 89 | - (void) onExit; 90 | 91 | - (void) removeFromParentAndCleanup :(bool)cleanup; 92 | 93 | // private update method to avoid collision with update: 94 | - (void) updatePrivate :(float)delta; 95 | @end 96 | -------------------------------------------------------------------------------- /Nodes/Node.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Node.mm 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Node.h" 30 | #import "Action.h" 31 | #include "CCNode.h" 32 | #include "CCComponent.h" 33 | #include "CCAction.h" 34 | 35 | namespace { 36 | // wrapper to access update 37 | class updateComponent 38 | : public cocos2d::Component 39 | { 40 | public: 41 | static updateComponent* create(Node* instance) 42 | { 43 | auto ret = new updateComponent(instance); 44 | if (ret && ret->init()) 45 | { 46 | ret->autorelease(); 47 | } 48 | else 49 | { 50 | CC_SAFE_DELETE(ret); 51 | } 52 | return ret; 53 | } 54 | updateComponent(Node* instance) 55 | : _instance(instance) 56 | {} 57 | protected: 58 | void update(float delta) 59 | { 60 | [_instance updatePrivate:delta]; 61 | } 62 | protected: 63 | SEL _selector; 64 | id _instance; 65 | }; 66 | } 67 | 68 | @implementation Node 69 | 70 | + (Node*) create 71 | { 72 | Node* node = [[Node alloc] init]; 73 | [node autorelease]; 74 | return node; 75 | } 76 | 77 | - (id) init 78 | { 79 | self.inner = cocos2d::Node::create(); 80 | [self initCommon]; 81 | return self; 82 | } 83 | 84 | - (void) dealloc 85 | { 86 | [_children release]; 87 | self.inner = nil; 88 | [super dealloc]; 89 | } 90 | 91 | - (void) initCommon 92 | { 93 | INNER(n,Node); 94 | n->setOnEnterCallback([self] () { [self onEnter]; }); 95 | n->setOnExitCallback([self] () { [self onExit]; }); 96 | } 97 | 98 | - (void) setAnchorPoint :(CGPoint)anchor 99 | { 100 | INNER(n,Node); 101 | n->setAnchorPoint(cocos2d::Vec2(anchor.x, anchor.y)); 102 | } 103 | 104 | - (CGPoint) getAnchorPoint 105 | { 106 | INNER(n,Node); 107 | auto ap = n->getAnchorPoint(); 108 | return CGPointMake(ap.x, ap.y); 109 | } 110 | 111 | - (float) getRotation 112 | { 113 | INNER(n,Node); 114 | return n->getRotation(); 115 | } 116 | 117 | - (void) setRotation :(float)r 118 | { 119 | INNER(n,Node); 120 | n->setRotation(r); 121 | } 122 | 123 | - (void) setOpacity :(float)a 124 | { 125 | INNER(n,Node); 126 | n->setOpacity(a); 127 | } 128 | 129 | - (float) getOpacity 130 | { 131 | INNER(n,Node); 132 | return n->getOpacity(); 133 | } 134 | 135 | - (void) setPosition :(CGPoint)pos 136 | { 137 | INNER(n,Node); 138 | n->setPosition(pos.x, pos.y); 139 | } 140 | 141 | - (void) setPosition :(float) x : (float) y 142 | { 143 | INNER(n,Node); 144 | n->setPosition(cocos2d::Point(x, y)); 145 | } 146 | 147 | - (CGPoint) getPosition 148 | { 149 | INNER(n,Node); 150 | const cocos2d::Vec2& pos = n->getPosition(); 151 | return CGPointMake(pos.x, pos.y); 152 | } 153 | 154 | - (void) setScaleX :(float)scaleX 155 | { 156 | INNER(n,Node); 157 | n->setScaleX(scaleX); 158 | } 159 | 160 | - (void) setScaleY :(float)scaleY 161 | { 162 | INNER(n,Node); 163 | n->setScaleY(scaleY); 164 | } 165 | 166 | - (void) setScaleZ :(float)scaleZ 167 | { 168 | INNER(n,Node); 169 | n->setScaleZ(scaleZ); 170 | } 171 | 172 | - (float) getScaleX 173 | { 174 | INNER(n,Node); 175 | return n->getScaleX(); 176 | } 177 | 178 | - (float) getScaleY 179 | { 180 | INNER(n,Node); 181 | return n->getScaleY(); 182 | } 183 | 184 | - (float) getScaleZ 185 | { 186 | INNER(n,Node); 187 | return n->getScaleZ(); 188 | } 189 | 190 | - (void) setScale :(float)scale 191 | { 192 | INNER(n,Node); 193 | n->setScale(scale); 194 | } 195 | 196 | - (float) getScale 197 | { 198 | INNER(n,Node); 199 | return n->getScale(); 200 | } 201 | 202 | - (void) setScale :(float)scaleX :(float)scaleY 203 | { 204 | INNER(n,Node); 205 | n->setScale(scaleX, scaleY); 206 | } 207 | 208 | - (void) addChild:(Node*) child 209 | { 210 | INNER(n,Node); 211 | [self retain]; 212 | n->addChild(static_cast(child.inner)); 213 | } 214 | 215 | - (void) removeChild :(Node*)child 216 | { 217 | INNER(n,Node); 218 | n->removeChild(static_cast(child.inner)); 219 | [self release]; 220 | } 221 | 222 | - (NSArray*) getChildren 223 | { 224 | if (_children == nil) 225 | _children = [[NSMutableArray alloc] init]; 226 | 227 | [_children removeAllObjects]; 228 | 229 | auto n = (cocos2d::Node*)_inner; 230 | for (auto node : n->getChildren()) 231 | [_children addObject:static_cast(node->_scriptObject)]; 232 | 233 | return _children; 234 | } 235 | 236 | - (Node*) getParent 237 | { 238 | INNER(n, Node); 239 | auto parent = n->getParent(); 240 | return parent != nullptr ? static_cast(parent->_scriptObject) : nullptr; 241 | } 242 | 243 | - (void) removeAllChildren 244 | { 245 | INNER(n, Node); 246 | NSMutableArray* outers = [[NSMutableArray alloc] initWithCapacity:n->getChildren().size()]; 247 | for (auto node : n->getChildren()) 248 | [outers addObject:GET_OUTER(node, Node)]; 249 | 250 | n->removeAllChildren(); 251 | 252 | for (id outer in outers) 253 | [outer release]; 254 | 255 | [outers release]; 256 | } 257 | 258 | - (CGSize) getContentSize 259 | { 260 | INNER(n,Node); 261 | auto size = n->getContentSize(); 262 | return CGSizeMake(size.width, size.height); 263 | } 264 | 265 | - (void) setContentSize :(CGSize)size 266 | { 267 | INNER(n,Node); 268 | n->setContentSize(cocos2d::Size(size.width, size.height)); 269 | } 270 | 271 | - (void) scheduleUpdate :(tUpdateBlock)update 272 | { 273 | _update = update; 274 | [_update retain]; 275 | INNER(n,Node); 276 | if (!n->getComponent("updateComponent")) 277 | { 278 | auto uc = updateComponent::create(self); 279 | uc->setName("updateComponent"); 280 | n->addComponent(uc); 281 | } 282 | n->scheduleUpdate(); 283 | } 284 | 285 | - (void) unscheduleUpdate 286 | { 287 | INNER(n,Node); 288 | // cannot remove this safely, rely on Node to remove 289 | //n->removeComponent("updateComponent"); 290 | n->unscheduleUpdate(); 291 | [_update release]; 292 | _update = nil; 293 | } 294 | 295 | - (CGPoint) convertToNodeSpace :(CGPoint)worldPoint 296 | { 297 | INNER(n,Node); 298 | auto np = n->convertToNodeSpace(cocos2d::Vec2(worldPoint.x, worldPoint.y)); 299 | return CGPointMake(np.x, np.y); 300 | } 301 | 302 | - (CGPoint) convertToWorldSpace :(CGPoint)nodePoint 303 | { 304 | INNER(n,Node); 305 | auto wp = n->convertToWorldSpace(cocos2d::Vec2(nodePoint.x, nodePoint.y)); 306 | return CGPointMake(wp.x, wp.y); 307 | } 308 | 309 | - (Action*) runAction :(Action*)action 310 | { 311 | INNER(n,Node); 312 | auto r = n->runAction(static_cast(action.inner)); 313 | SET_OUTER(r,Action); 314 | return GET_OUTER(r,Action); 315 | } 316 | 317 | - (void) stopAction :(Action*)action 318 | { 319 | INNER(n,Node); 320 | n->stopAction(static_cast(action.inner)); 321 | } 322 | 323 | - (void) stopAllActions 324 | { 325 | INNER(n,Node); 326 | n->stopAllActions(); 327 | } 328 | 329 | - (void) onEnter 330 | { 331 | // does nothing 332 | } 333 | 334 | - (void) onExit 335 | { 336 | // does nothing 337 | } 338 | 339 | - (void) removeFromParentAndCleanup :(bool)cleanup 340 | { 341 | INNER(n,Node); 342 | n->removeFromParentAndCleanup(cleanup); 343 | } 344 | 345 | // 346 | // Private Methods 347 | // 348 | 349 | - (void) updatePrivate :(float)delta 350 | { 351 | if (nil != _update) 352 | _update(delta); 353 | } 354 | @end 355 | -------------------------------------------------------------------------------- /Nodes/Scene.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Scene.h 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Node.h" 30 | 31 | @interface Scene : Node 32 | + (Scene*) create; 33 | @end 34 | -------------------------------------------------------------------------------- /Nodes/Scene.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Scene.mm 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Scene.h" 30 | #include "CCScene.h" 31 | 32 | @implementation Scene 33 | + (Scene*) create 34 | { 35 | return [[self alloc] init]; 36 | } 37 | 38 | - (id) init 39 | { 40 | self.inner = cocos2d::Scene::create(); 41 | [self initCommon]; 42 | return self; 43 | } 44 | 45 | - (void) dealloc 46 | { 47 | [self removeAllChildren]; 48 | [super dealloc]; 49 | } 50 | @end 51 | -------------------------------------------------------------------------------- /Nodes/Sprite.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Sprite.h 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Node.h" 30 | 31 | @interface Sprite : Node 32 | + (Sprite*) create :(NSString*)filename; 33 | @end 34 | -------------------------------------------------------------------------------- /Nodes/Sprite.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Sprite.mm 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Sprite.h" 30 | #include "CCSprite.h" 31 | 32 | @implementation Sprite 33 | + (Sprite*) create :(NSString*) filename 34 | { 35 | return [[self alloc] initWithFile:filename]; 36 | } 37 | 38 | - (id) initWithFile:(NSString*)filename 39 | { 40 | self.inner = cocos2d::Sprite::create([filename UTF8String]); 41 | [self initCommon]; 42 | return self; 43 | } 44 | @end 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cocos2d-x-swift-bindings 2 | ======================== 3 | 4 | Swift bindings for cocos2d-x 5 | -------------------------------------------------------------------------------- /System/Color.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Color.h 27 | // Created by Justin Graham on 7/7/14. 28 | 29 | #import "Ref.h" 30 | 31 | @interface Color4B : Ref 32 | @property (nonatomic,assign) unsigned char r; 33 | @property (nonatomic,assign) unsigned char g; 34 | @property (nonatomic,assign) unsigned char b; 35 | @property (nonatomic,assign) unsigned char a; 36 | + (id) createWithRGBA :(unsigned char)red :(unsigned char)green :(unsigned char)blue :(unsigned char)alpha; 37 | + (id) createWithBlack; 38 | @end 39 | -------------------------------------------------------------------------------- /System/Color.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Color.mm 3 | // SwiftTetris 4 | // 5 | // Created by Justin Graham on 7/7/14. 6 | // 7 | // 8 | 9 | #import "Color.h" 10 | 11 | @implementation Color4B 12 | + (id) createWithRGBA :(unsigned char)red :(unsigned char)green :(unsigned char)blue :(unsigned char)alpha 13 | { 14 | Color4B* color = [Color4B new]; 15 | color.r = red; 16 | color.g = green; 17 | color.b = blue; 18 | color.a = alpha; 19 | return color; 20 | } 21 | 22 | + (id) createWithBlack 23 | { 24 | Color4B* color = [Color4B new]; 25 | color.r = 0; 26 | color.g = 0; 27 | color.b = 0; 28 | color.a = 255; 29 | return color; 30 | } 31 | @end -------------------------------------------------------------------------------- /System/Console.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Console.h 27 | // Created by Justin Graham on 6/30/14. 28 | 29 | #import "Ref.h" 30 | 31 | typedef void(^commandBlock)(int, NSString*); 32 | 33 | @interface Console : Ref 34 | - (void) listenOnTCP :(int)port; 35 | - (void) log :(NSString*)text; 36 | - (void) addCommand :(NSString*)name :(NSString*)help :(commandBlock)command; 37 | @end 38 | -------------------------------------------------------------------------------- /System/Console.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Console.mm 27 | // Created by Justin Graham on 6/30/14. 28 | 29 | #import "Console.h" 30 | #include "CCConsole.h" 31 | 32 | @implementation Console 33 | - (void) listenOnTCP :(int)port 34 | { 35 | INNER(c,Console); 36 | c->listenOnTCP(port); 37 | } 38 | 39 | - (void) log :(NSString*)text 40 | { 41 | INNER(c,Console); 42 | c->log([text UTF8String]); 43 | c->log("\n"); 44 | } 45 | 46 | - (void) addCommand :(NSString*)name :(NSString*)help :(commandBlock)command 47 | { 48 | INNER(c,Console); 49 | [command retain]; 50 | auto lambda = [command](int i, const std::string& s) 51 | { 52 | command(i, [[NSString alloc] initWithUTF8String:s.c_str()]); 53 | }; 54 | cocos2d::Console::Command m = {[name UTF8String], [help UTF8String], lambda}; 55 | c->addCommand(m); 56 | } 57 | @end 58 | -------------------------------------------------------------------------------- /System/Director.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Director.h 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Ref.h" 30 | #import "Scene.h" 31 | 32 | @class EventDispatcher; 33 | @class Console; 34 | @class AudioEngine; 35 | 36 | @interface Director : Ref 37 | { 38 | // EventDispatcher* _eventDispatcher; 39 | // Console* _console; 40 | // AudioEngine* _audioEngine; 41 | } 42 | + (Director*) getInstance; 43 | - (void) runWithScene :(Scene*)scene; 44 | - (void) pushScene :(Scene*)scene; 45 | - (void) popScene; 46 | - (void) replaceScene :(Scene*)scene; 47 | - (CGSize) getWinSize; 48 | @property (nonatomic,retain) Console* console; 49 | @property (nonatomic,retain) EventDispatcher* eventDispatcher; 50 | @property (nonatomic,retain) AudioEngine* audioEngine; 51 | @end 52 | -------------------------------------------------------------------------------- /System/Director.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Director.mm 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Director.h" 30 | #import "Scene.h" 31 | #import "Console.h" 32 | #import "EventDispatcher.h" 33 | #include "CCDirector.h" 34 | #include "CCScene.h" 35 | #include "CCConsole.h" 36 | 37 | @implementation Director 38 | + (Director*) getInstance 39 | { 40 | static Director* instance = nil; 41 | static dispatch_once_t onceToken; 42 | dispatch_once(&onceToken, ^{ 43 | instance = [[self alloc] init]; 44 | instance.inner = cocos2d::Director::getInstance(); 45 | 46 | }); 47 | return instance; 48 | } 49 | 50 | - (void) runWithScene:(Scene*)scene 51 | { 52 | INNER(director,Director); 53 | [scene retain]; 54 | director->runWithScene(static_cast(scene.inner)); 55 | } 56 | 57 | - (void) pushScene:(Scene*)scene 58 | { 59 | INNER(director,Director); 60 | [scene retain]; 61 | director->pushScene(static_cast(scene.inner)); 62 | } 63 | 64 | - (void) popScene 65 | { 66 | INNER(director,Director); 67 | auto scene = director->getRunningScene(); 68 | auto s = GET_OUTER(scene,Scene); 69 | [s release]; 70 | director->popScene(); 71 | } 72 | 73 | - (void) replaceScene :(Scene*)scene 74 | { 75 | INNER(director,Director); 76 | auto old = director->getRunningScene(); 77 | if (old) 78 | { 79 | auto s = GET_OUTER(old,Scene); 80 | [s release]; 81 | } 82 | [scene retain]; 83 | director->replaceScene(static_cast(scene.inner)); 84 | } 85 | 86 | - (CGSize) getWinSize 87 | { 88 | INNER(director,Director); 89 | auto size = director->getWinSize(); 90 | return CGSizeMake(size.width, size.height); 91 | } 92 | 93 | - (EventDispatcher*) eventDispatcher 94 | { 95 | if (nil == _eventDispatcher) 96 | _eventDispatcher = [[EventDispatcher alloc] init]; 97 | return _eventDispatcher; 98 | } 99 | 100 | - (Console*) console 101 | { 102 | if (nil == _console) 103 | { 104 | INNER(director,Director); 105 | auto console = director->getConsole(); 106 | SET_OUTER(console, Console); 107 | _console = GET_OUTER(console, Console); 108 | _console.inner = console; 109 | } 110 | return _console; 111 | } 112 | @end 113 | 114 | -------------------------------------------------------------------------------- /System/Ref.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Ref.h 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Foundation/Foundation.h" 30 | #import "CoreGraphics/CoreGraphics.h" 31 | 32 | @interface Ref : NSObject 33 | { 34 | @protected 35 | void* _inner; 36 | } 37 | - (id) retain; 38 | - (void) release; 39 | @property (assign,nonatomic) void* inner; 40 | @end 41 | 42 | #define INNER(v,T) cocos2d::T* v = static_cast(self.inner) 43 | #define INNERNS(v,T) T* v = static_cast(self.inner) 44 | 45 | #define GET_OUTER(v,T) static_cast(v->_scriptObject) 46 | 47 | #define SET_OUTER(v,T) \ 48 | if (nullptr == v->_scriptObject) \ 49 | { \ 50 | T* t = [[T alloc] init]; \ 51 | t.inner = v; \ 52 | v->_scriptObject = t; \ 53 | } \ 54 | else \ 55 | { \ 56 | T* t = static_cast(v->_scriptObject); \ 57 | t.inner = v; \ 58 | } 59 | 60 | -------------------------------------------------------------------------------- /System/Ref.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Ref.mm 27 | // Created by Justin Graham on 6/17/14. 28 | 29 | #import "Ref.h" 30 | #include "CCRef.h" 31 | #include "CCNode.h" 32 | 33 | @implementation Ref 34 | - (void) dealloc 35 | { 36 | if (_inner) 37 | { 38 | auto n = static_cast(_inner); 39 | n->release(); 40 | } 41 | [super dealloc]; 42 | } 43 | 44 | - (id) retain 45 | { 46 | auto ref = (cocos2d::Ref*)_inner; 47 | if (ref) 48 | ref->retain(); 49 | return [super retain]; 50 | } 51 | 52 | - (void) release 53 | { 54 | auto ref = (cocos2d::Ref*)_inner; 55 | if (ref) 56 | ref->release(); 57 | [super release]; 58 | } 59 | 60 | - (void*) inner 61 | { 62 | return _inner; 63 | } 64 | 65 | - (void) setInner:(void*)inner 66 | { 67 | if (_inner) 68 | { 69 | [self retain]; 70 | _inner = nil; 71 | } 72 | if (inner) 73 | { 74 | _inner = inner; 75 | [self retain]; 76 | auto n = static_cast(inner); 77 | n->_scriptObject = self; 78 | } 79 | } 80 | @end 81 | -------------------------------------------------------------------------------- /System/Utilities.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Utilities.h 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | @interface Utilities : NSObject 30 | + (double) random :(double)min :(double)max; 31 | @end 32 | -------------------------------------------------------------------------------- /System/Utilities.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Utilities.mm 27 | // Created by Justin Graham on 6/21/14. 28 | 29 | #import "Utilities.h" 30 | 31 | @implementation Utilities 32 | + (double) random :(double)min :(double)max 33 | { 34 | double norm = fabs(arc4random_uniform(uint32_t(max))) / max; 35 | return min + norm * (max - min); 36 | } 37 | @end 38 | -------------------------------------------------------------------------------- /UI/Widget.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Widget.h 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "Ref.h" 30 | 31 | @interface Widget : Ref 32 | @end 33 | -------------------------------------------------------------------------------- /UI/Widget.mm: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | Copyright (c) 2014 Chukong Technologies Inc. 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | // Widget.mm 27 | // Created by Justin Graham on 6/28/14. 28 | 29 | #import "Widget.h" 30 | 31 | @implementation Widget 32 | @end 33 | --------------------------------------------------------------------------------