void Button::ccTouchesBegan(CCSet* pTouches, CCEvent *pEvent) { if(!enable)return; CCPoint TouchesLocation = getTouchPos(pTouches); CCRect buttonRect=getBoundingBox(); if(!buttonRect.containsPoint(TouchesLocation))return; controllerListener->respond(0); return; }
void TouchScreen::teleportTo(CCSet* pTouch, CCEvent *pEvent) { CCTouch* touch=(CCTouch*)pTouch->anyObject(); if((touch->getLocation()-touch->getStartLocation()).getLength()>ZOOMSTROKELEN)return; if(doShrink||(!sGlobal->superPower->teleport&&!sGlobal->superPower->all))return; if(buttonA->getBoundingBox().containsPoint(getTouchPos(pTouch)))return; if(dirButton->getBoundingBox().containsPoint(getTouchPos(pTouch)))return; CCPoint BX=touch->getLocation(),BD=hero->map->getPosition(); CCPoint BA=ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height/2); CCPoint destPlace=BX-BA-(BD-BA)*0.3; int x=destPlace.x/(hero->map->getTileSize().width*EGLVIEW); int y=(((hero->map->getMapSize().height)*hero->map->getTileSize().height*EGLVIEW) -destPlace.y)/(hero->map->getTileSize().height*EGLVIEW); CCPoint mapTileCoord=ccp(x,y); CCPoint touchTilePos=hero->map->tileCoordFromPosition(touch->getLocation()); CCPoint touchTiledPos=hero->map->positionFromTileCoord(touchTilePos); CCPoint mapTileMove=hero->map->humanPosForTileMove(mapTileCoord); CCSequence* teleport=CCSequence::create(CCDelayTime::create(0.5f), Animation::getAction(TELEPORTOUT,hero->getChildByTag(IMGSP)->getContentSize()), CCDelayTime::create(0.40f), Animation::getAction(TELEPORTIN,hero->getChildByTag(IMGSP)->getContentSize()), NULL); CCScaleTo* mapLayerMove=CCScaleTo::create(0.5f,1.0f); CCSequence* mapMove=CCSequence::create(CCDelayTime::create(0.5f), CCDelayTime::create(0.2f),CCMoveTo::create(0.3f,mapTileMove),NULL); doShrink=!doShrink; hero->runAction(teleport); hero->map->runAction(mapMove); hero->map->getParent()->runAction(mapLayerMove); sGlobal->mapState->positionX=hero->getHeroTilePos().x; sGlobal->mapState->positionY=hero->getHeroTilePos().y; sGlobal->mapState->faceDir=hero->dir; }
/* * Handle Touch Inputs */ static int32_t handle_touch_input(AInputEvent *event) { pthread_t thisthread = pthread_self(); LOG_EVENTS_DEBUG("handle_touch_input(%X), pthread_self() = %X", event, thisthread); switch(AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK) { case AMOTION_EVENT_ACTION_DOWN: { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_DOWN"); int pointerId = AMotionEvent_getPointerId(event, 0); float xP = AMotionEvent_getX(event,0); float yP = AMotionEvent_getY(event,0); LOG_EVENTS_DEBUG("Event: Action DOWN x=%f y=%f pointerID=%d\n", xP, yP, pointerId); int pId = pointerId; float x = xP; float y = yP; cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &pId, &x, &y); return 1; } break; case AMOTION_EVENT_ACTION_POINTER_DOWN: { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_POINTER_DOWN"); int pointerIndex = AMotionEvent_getAction(event) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; int pointerId = AMotionEvent_getPointerId(event, pointerIndex); float xP = AMotionEvent_getX(event,pointerIndex); float yP = AMotionEvent_getY(event,pointerIndex); LOG_EVENTS_DEBUG("Event: Action POINTER DOWN x=%f y=%f pointerID=%d\n", xP, yP, pointerId); int pId = pointerId; float x = xP; float y = yP; cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &pId, &x, &y); return 1; } break; case AMOTION_EVENT_ACTION_MOVE: { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_MOVE"); int pointerCount = AMotionEvent_getPointerCount(event); int ids[pointerCount]; float xs[pointerCount], ys[pointerCount]; getTouchPos(event, ids, xs, ys); cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(pointerCount, ids, xs, ys); return 1; } break; case AMOTION_EVENT_ACTION_UP: { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_UP"); int pointerId = AMotionEvent_getPointerId(event, 0); float xP = AMotionEvent_getX(event,0); float yP = AMotionEvent_getY(event,0); LOG_EVENTS_DEBUG("Event: Action UP x=%f y=%f pointerID=%d\n", xP, yP, pointerId); int pId = pointerId; float x = xP; float y = yP; cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &pId, &x, &y); return 1; } break; case AMOTION_EVENT_ACTION_POINTER_UP: { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_POINTER_UP"); int pointerIndex = AMotionEvent_getAction(event) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; int pointerId = AMotionEvent_getPointerId(event, pointerIndex); float xP = AMotionEvent_getX(event,pointerIndex); float yP = AMotionEvent_getY(event,pointerIndex); LOG_EVENTS_DEBUG("Event: Action POINTER UP x=%f y=%f pointerID=%d\n", xP, yP, pointerIndex); int pId = pointerId; float x = xP; float y = yP; cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &pId, &x, &y); return 1; } break; case AMOTION_EVENT_ACTION_CANCEL: { LOG_EVENTS_DEBUG("AMOTION_EVENT_ACTION_CANCEL"); int pointerCount = AMotionEvent_getPointerCount(event); int ids[pointerCount]; float xs[pointerCount], ys[pointerCount]; getTouchPos(event, ids, xs, ys); cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(pointerCount, ids, xs, ys); return 1; } break; default: LOG_EVENTS_DEBUG("handle_touch_input() default case.... NOT HANDLE"); return 0; break; } }