auto pokerFront = Sprite::create("images/poker_dj.jpg"); pokerFront->setPosition(ccp(visibaleSize.width*0.3, visibaleSize.height/2)); pokerFront->setVisible(false); addChild(pokerFront, 1, 1); auto pokerBack = Sprite::create("images/poker_background.jpg"); pokerBack->setPosition(ccp(visibaleSize.width*0.3, visibaleSize.height/2)); addChild(pokerBack, 1, 2); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = [](Touch* touch, Event* event) { auto target = event->getCurrentTarget(); Point clickedPoint = target->convertTouchToNodeSpace(touch); Size s = target->getContentSize(); Rect rect(0, 0, s.width, s.height); if (rect.containsPoint(clickedPoint)) { return true; } return false; }; listener->onTouchEnded = [this](Touch* touch, Event* event) { static bool isTurnning = false; if (!isTurnning) { isTurnning = true; Sprite* pokerFront = static_cast<Sprite*>(this->getChildByTag(1)); Sprite* pokerBack = (Sprite*)this->getChildByTag(2); std::function<void(Sprite*, Sprite*)> turnFunc = [](Sprite* pokerA, Sprite* pokerB) { auto targetedAction = TargetedAction::create(pokerA , Sequence::createWithTwoActions(Show::create(), OrbitCamera::create(0.5, 1, 0, 270, 90, 0, 0))); auto turnAction = Sequence::create(OrbitCamera::create(0.5, 1, 0, 0, 90, 0, 0) , Hide::create() , targetedAction , CallFunc::create([]{isTurnning = false;}) , nullptr); pokerB->runAction(turnAction); }; if (pokerBack->isVisible()) { turnFunc(pokerFront, pokerBack); } else { turnFunc(pokerBack, pokerFront); } } }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, pokerBack);