Skip to content

Instantly share code, notes, and snippets.

@SpaghettDev
Created May 18, 2025 18:02
Show Gist options
  • Save SpaghettDev/a37d3a2a5becec4624e4a3506c2e64b8 to your computer and use it in GitHub Desktop.
Save SpaghettDev/a37d3a2a5becec4624e4a3506c2e64b8 to your computer and use it in GitHub Desktop.
CCNode that receives touches.
#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);
}
#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