Created
May 18, 2025 18:02
-
-
Save SpaghettDev/a37d3a2a5becec4624e4a3506c2e64b8 to your computer and use it in GitHub Desktop.
CCNode that receives touches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "TouchableNode.hpp" | |
#include <Geode/cocos/touch_dispatcher/CCTouchDispatcher.h> | |
void TouchableNode::onEnter() | |
{ | |
registerWithTouchDispatcher(); | |
CCNode::onEnter(); | |
} | |
void TouchableNode::onExit() | |
{ | |
unregisterWithTouchDispatcher(); | |
CCNode::onExit(); | |
} | |
bool TouchableNode::ccTouchBegan(cocos2d::CCTouch*, cocos2d::CCEvent*) | |
{ | |
return true; | |
} | |
void TouchableNode::ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) | |
{ | |
// touch moved | |
} | |
void TouchableNode::ccTouchEnded(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) | |
{ | |
// touch ended | |
} | |
void TouchableNode::registerWithTouchDispatcher() | |
{ | |
CCTouchDispatcher::get()->addStandardDelegate(this, 0); | |
} | |
void TouchableNode::unregisterWithTouchDispatcher() | |
{ | |
CCTouchDispatcher::get()->removeDelegate(this); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Geode/cocos/base_nodes/CCNode.h> | |
#include <Geode/cocos/touch_dispatcher/CCTouchDelegateProtocol.h> | |
class TouchableNode : public cocos2d::CCNode, public cocos2d::CCTouchDelegate | |
{ | |
public: | |
virtual void onEnter() override; | |
virtual void onExit() override; | |
virtual bool ccTouchBegan(cocos2d::CCTouch*, cocos2d::CCEvent*) override; | |
virtual void ccTouchMoved(cocos2d::CCTouch*, cocos2d::CCEvent*) override; | |
virtual void ccTouchEnded(cocos2d::CCTouch*, cocos2d::CCEvent*) override; | |
void registerWithTouchDispatcher(); | |
void unregisterWithTouchDispatcher(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment