void LCCrossMatchGame::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) { // 멀티터치 금지 if (singleTouch != NULL) { return; } CCTouch *touch = (CCTouch*)pTouches->anyObject(); singleTouch = touch; prevTouchLocation = touch->locationInView( touch->view() ); moveAmount = 0; m_pTouchedDotSprite = NULL; for (int i=0; i<m_pDotSprites->count(); i++) { CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i); if (LCUtil::isTouchInside(dotSprite, pTouches)) { m_pTouchedDotSprite = dotSprite; break; } } // image touch 및 text label touch 구역 추가 on 11.10.17 if (!m_pTouchedDotSprite) { for (int i=0; i<m_pImageArray->count(); i++) { CCSprite *imageSprite = (CCSprite *)m_pImageArray->objectAtIndex(i); if (LCUtil::isTouchInside(imageSprite, pTouches)) { // dotArray에 이미지 부분부터 추가되므로 for (int i=0; i<m_pDotSprites->count(); i++) { CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i); if (dotSprite->getTag() == imageSprite->getTag()) { m_pTouchedDotSprite = dotSprite; break; } } } } } if (!m_pTouchedDotSprite) { for (int i=0; i<m_pTextArray->count(); i++) { CCLabelTTF *textLabel = (CCLabelTTF*)m_pTextArray->objectAtIndex(i); if (LCUtil::isTouchInside(textLabel, pTouches)) { // dotArray에 이미지 부분부터 추가되므로 뒤에서부터 탐색 for (int i=m_pDotSprites->count()-1; i>=0; i--) { CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i); if (dotSprite->getTag() == textLabel->getTag()) { m_pTouchedDotSprite = dotSprite; break; } } } } } }
void LCCrossMatchGame::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) { if (m_pTouchedDotSprite) { CCSprite *matchedDotSprite = NULL; bool isTouchedIncorrectly = false; // 다른 점을 터치 했는지 체크 for (int i=0; i<m_pDotSprites->count(); i++) { CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i); if (m_pTouchedDotSprite == dotSprite) { continue; } if (LCUtil::isTouchInside(dotSprite, pTouches)) { //move dots from dot array to finished dot array if (dotSprite->getTag() == m_pTouchedDotSprite->getTag()) { matchedDotSprite = dotSprite; }else { isTouchedIncorrectly = true; } break; } } // image touch 및 text label touch 구역 추가 on 11.10.17 if (!matchedDotSprite && !isTouchedIncorrectly) { int index = m_pDotSprites->indexOfObject(m_pTouchedDotSprite); if (index < m_pDotSprites->count() / 2) { // 앞쪽에 있는 것은 image 부분에 있는 점 => text부분 터치 체크 for (int i=0; i<m_pTextArray->count(); i++) { CCLabelTTF *textLabel = (CCLabelTTF*)m_pTextArray->objectAtIndex(i); if (LCUtil::isTouchInside(textLabel, pTouches)) { if (textLabel->getTag() == m_pTouchedDotSprite->getTag()) { // dotArray에 이미지 부분부터 추가되므로 뒤에서부터 탐색 for (int i=m_pDotSprites->count()-1; i>=0; i--) { CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i); if (dotSprite->getTag() == textLabel->getTag()) { matchedDotSprite = dotSprite; break; } } }else { isTouchedIncorrectly = true; } break; } } } else { // 뒤쪽에 있는 것은 text부분에 있는 점 => image 부분 터치 체크 for (int i=0; i<m_pImageArray->count(); i++) { CCSprite *imageSprite = (CCSprite *)m_pImageArray->objectAtIndex(i); if (LCUtil::isTouchInside(imageSprite, pTouches)) { if (imageSprite->getTag() == m_pTouchedDotSprite->getTag()) { // dotArray에 이미지 부분부터 추가되므로 for (int i=0; i<m_pDotSprites->count(); i++) { CCSprite *dotSprite = (CCSprite *)m_pDotSprites->objectAtIndex(i); if (dotSprite->getTag() == imageSprite->getTag()) { matchedDotSprite = dotSprite; break; } } }else { isTouchedIncorrectly = true; } } } } } // 올바르게 터치된 점이 있다면 if (matchedDotSprite) { m_pFinishedDotSprites->addObject(m_pTouchedDotSprite); m_pFinishedDotSprites->addObject(matchedDotSprite); m_pDotSprites->removeObject(m_pTouchedDotSprite); m_pDotSprites->removeObject(matchedDotSprite); // 터치된 스프라이트 찾기 CCSprite* matchedSprite = NULL; for (int i=0; i<m_pImageArray->count(); i++) { CCSprite* sprite = (CCSprite*)m_pImageArray->objectAtIndex(i); if (sprite->getTag() == matchedDotSprite->getTag()) { matchedSprite = sprite; break; } } this->didMatchWord(); this->didMatchWord(matchedSprite, m_pIndexArray, matchedDotSprite->getTag()); drawMatchedLines(); if (m_pDotSprites->count() == 0) { //CCLog("finished"); this->didFinishedStage(); //load CCSequence* seq = CCSequence::actions(CCDelayTime::actionWithDuration(this->delayTimeOfChangeWord(m_pIndexArray, m_iIndex)), CCCallFunc::actionWithTarget(this, callfunc_selector(LCCrossMatchGame::didDelayedChangeWord)) ,NULL); this->runAction(seq); //this->loadSprites(); } m_pTouchedDotSprite = NULL; singleTouch = NULL; return; } // 만일 잘못된 연결을 했을경우 if (isTouchedIncorrectly) { this->didMissMatchWord(); drawMatchedLines(); m_pTouchedDotSprite = NULL; singleTouch = NULL; return; } } drawMatchedLines(); // 점을 터치 한 것이 아니라 다른 것을 터치했을경우 // 이미지 터치 체크 CCTouch* touch = (CCTouch*)pTouches->anyObject(); CCPoint touchLocation = touch->locationInView( touch->view() ); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); for (int i=0; i<m_pImageArray->count(); i++) { CCSprite* imageSprite = (CCSprite*) m_pImageArray->objectAtIndex(i); // added by YoungJae Kwon // 태호씨 LCUtil의 isTouchInside depricate 시키세요~ 대신 CCRectContainsPoint랑 convetToNodeSpace 섞어서 쓰시길 // if (LCUtil::isTouchInside(imageSprite, pTouches)) { if( CCRect::CCRectContainsPoint(imageSprite->getRect(), imageSprite->getParent()->convertToNodeSpace(touchLocation)) ) { this->didWordImagedTouched(imageSprite, m_pIndexArray, imageSprite->getTag()); } } m_pTouchedDotSprite = NULL; singleTouch = NULL; }