コード例 #1
0
ファイル: QTELayer.cpp プロジェクト: NjAiYo/MonsterGame
void QTELayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event)
{
    if(!enableFight) return;
    Touch *touch = touches.at(0);
    Vec2 delta = touch->getDelta();
    Vec2 lastPos = touch->getPreviousLocation();
    Vec2 pos = touch->getLocation();
    
    float dx = pos.x - startTouchPosition.x;
    float dy = pos.y - startTouchPosition.y;
    float dist = sqrtf(dx*dx+dy*dy);
    
    
    streak->setPosition(pos);
    //刀的判断
    dist = pos.distanceSquared(startTouchPosition);
    
    if (dist > 50) {
        //hit test monster
        bool hit = qteMonster->hittestPoint(pos);
        if (hit) {
            hitQteMonster();
        }
    }
}
コード例 #2
0
//=============================================================
//=============================================================
void CCScrollLayer::onTouchMoved(Touch *pTouch, Event *pEvent)
{
	//CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	//CCSetIterator it = pTouches->begin();
    Touch* touch = pTouch;
	
	Point movePoint = touch->getLocation();
	Point prePoint = touch->getPreviousLocation();
    
    if(!m_containBeginTouchPointFlag)
        return;
    
    float fMoveX = movePoint.x - prePoint.x;
    float fMoveY = movePoint.y - prePoint.y;
    m_2fLastMoveDis = vertex2(fMoveX, fMoveY);
    
    Node* parent = getParent();
    Point localPoint = parent->convertToNodeSpace(movePoint);
    Rect boundRect = boundingBox();
    
    if(boundRect.containsPoint(localPoint))
    {
        float moveX = movePoint.x - prePoint.x;
        float moveY = movePoint.y - prePoint.y;
        
        Point movePoint = Point::ZERO;
        
        if(m_HMoveAbleFlag)    //横竖是否可移动
        {
            if(m_boundsDragOriation.HOriention != DOE_UNKNOWN) //没超出边界时
            {
                moveX *= m_percentOfMoveWhenDragOut;
            }
            movePoint = Point(m_contentLayer->getPosition().x + moveX,m_contentLayer->getPosition().y);
            
        }
        if(m_VMoveAbleFlag)
        {
            if(m_boundsDragOriation.VOriention != DOE_UNKNOWN) //没超出边界时
            {
                moveY *= m_percentOfMoveWhenDragOut;
            }
            movePoint = Point(movePoint.x,m_contentLayer->getPosition().y + moveY);
        }
        
        refreshDragOrientation(movePoint);     //移动时刷新数据
        m_contentLayer->setPosition(movePoint);  
        refreshDotPosition();
        sendSelector(SSTE_TOUCH_MOVE);
                  
    }
    else //手势移动到边界之外  可能不进入
    {
        m_containBeginTouchPointFlag = false;
        if(m_pagingEnable == true)
        {
            nextPageAction(localPoint);
        }
        else
        {
            moveToEndPosition(false,m_contentLayer->getPosition());
            sendSelector(SSTE_TOUCH_END);
           // beginDeclerate();  //开始减速
        }
    }
    
}