首页 > 其他 > 详细

连连看源码分析-五

时间:2014-04-22 19:37:15      阅读:573      评论:0      收藏:0      [点我收藏+]

五、触摸处理ccTouchEnded()
1、获取触摸屏幕的坐标转换成地图坐标
2、判断该是否在有效范围、是否为空
3、播放触摸声音
4、根据点击坐标获取精灵、并放大1.3倍
5、根据坐标获取前一个点击的精灵
6、比较这两精灵是否可以连接消除
 是,播放消除声音,清除这两坐标node,隐藏这两精灵
 否,缩小前一个精灵,并有抖动动画
7、把当前点击坐标赋值于前一个坐标. (前一坐标初始值(-1, -1))


 

//触摸结束
void MapLayer::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{


    CCPoint location = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView()); //获取触摸屏幕的坐标
	location = this->convertToNodeSpace(location);
    
    //location=CCPointMake(location.x, location.y-40);
    
    location=this->pointOfView(location);
    
    
      CCLOG("x:%f",location.x);
      CCLOG("y:%f",location.y);

    if (this->isValiableNode(location)==false)
    {
        return;
    }
    
    if (this->isEmptyNode(location))
    {
        return;
    }

    

    SimpleAudioEngine::sharedEngine()->playEffect("12.wav");
    
    
    
    if (this->isSamePoints(location, prePoint))
    {
        return;
    }
    
    //点击当前精灵
    CCSprite *spritecurrent=(CCSprite *)this->getChildByTag(TAG_START_SPRITE+this->indexFromPoint(location));
    spritecurrent->setScale(1.3); //放大

    CCLOG("%d",this->indexFromPoint(location));
    
    if (this->isValiableNode(prePoint))
    {
    
        //前一个
         CCSprite *spritepre=(CCSprite *)this->getChildByTag(TAG_START_SPRITE+this->indexFromPoint(prePoint));
        
        if (this->canClearTwo(prePoint, location))
        {
            
            SimpleAudioEngine::sharedEngine()->playEffect("4.wav");

            this->clearNode(location);
            this->clearNode(prePoint);
            
            
            spritecurrent->setVisible(false);
            spritepre->setVisible(false);
            
            
        }
        else
        {
        
        
            spritepre->setScale(0.9);
            
        
            this->scaleAnimation(spritepre);
        
        }
        
        
        
    }
    
    prePoint=location;

}


连连看源码分析-五,布布扣,bubuko.com

连连看源码分析-五

原文:http://blog.csdn.net/oyangyufu/article/details/24297597

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!