pgintro.net

タッチ処理

作成日時:2018/04/01

更新日時:2018/04/01

スポンサーリンク

タッチ処理

bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchCancelled(cocos2d::Touch* touch, cocos2d::Event* event);
bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
{
  Point touchPos = touch->getLocation();
}

void HelloWorld::onTouchMoved(Touch* touch, Event* event)
{
  Point touchPos = touch->getLocation();
}

void HelloWorld::onTouchEnded(Touch* touch, Event* event)
{
  Point touchPos = touch->getLocation();
}

void HelloWorld::onTouchCancelled(Touch* touch, Event* event)
{
  Point touchPos = touch->getLocation();
}
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
listener->onTouchCancelled = CC_CALLBACK_2(HelloWorld::onTouchCancelled, this);

EventDispatcher* dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);