0
내가 만진 카드의 객체를 감지하고 싶습니다. 카드는 코코스 스프라이트를 확장하는 사용자 정의 클래스입니다.어떤 확장 스프레드가 i를 터치했는지 감지
카드의 멤버 메소드를 호출하고 싶습니다. 뭔가 이런 : if (target is Card) target.openCard();
대단히 감사합니다. 나 C++처럼 보이지 않는
메인 클래스 바디
bool HelloWorld::init()
{
... some init code, generating card arrays, shuffling
// draw memory cards
int count = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
auto card = Card::createCard();
card->customInit(cardsPictures[count]);
this->addChild(card);
card->setPosition(100 + i*100, 600 - j*100);
count++;
}
}
// register event listener
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
touchListener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
touchListener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);
touchListener->onTouchCancelled = CC_CALLBACK_2(HelloWorld::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
}
bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
{
auto target = event->getCurrentTarget();
if (target is Card) target.openCard(); // not working
return true;
}