javascript选中精灵旋转缩放 移动操作

为了方便代码维护

所以统一给屏幕添加事件

判断点中哪个精灵需要 遍历每个精灵 判断是否与触摸 碰撞  碰撞就是触发哪个精灵处理

还有就是 单点触摸和多点触摸逻辑一定更要分离

就是1个手指第一次点击 算单点(2个手机送开1个手指就不能算进去 不然逻辑会乱) 所以这个地方要写判断是否全部松开的点击 为单点

 

 

bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) 
{ 
    int tag ;
    for (tag = 1;tag<=TagCount;tag++)
    {
        CCSprite* sprite= (CCSprite*)this->getChildByTag(tag); 

        CCPoint touchPoint = pTouch->getLocationInView();
        touchPoint = CCDirector::sharedDirector()->convertToGL( touchPoint );

        CCRect rc1 = sprite->boundingBox();
        if (rc1.containsPoint(touchPoint))
        { 
            pSprite = sprite;
            return true;
        }
    }
    return false; 
} 
void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) 
{
    CCPoint beginPoint=pTouch->getLocationInView(); 
    beginPoint=CCDirector::sharedDirector()->convertToGL(beginPoint); 

    CCPoint endPoint=pTouch->getPreviousLocationInView(); 
    endPoint=CCDirector::sharedDirector()->convertToGL(endPoint); 

    CCPoint offSet =ccpSub(beginPoint,endPoint); 
    CCPoint toPoint=ccpAdd(pSprite->getPosition(),offSet); 
    pSprite->setPosition(toPoint); 
}

 

然后结合如下 缩放旋转

 

http://developer.egret.com/cn/example/egret2d/index.html#060-interact-multi-point

 

 


https://www.cnblogs.com/newmiracle/p/12350677.html

posted @ 2020-03-20 17:15  newmiracle宇宙  阅读(155)  评论(0编辑  收藏  举报