• cocos2d-x的初步学习六


    这篇文章中,我们讲下渐隐效果,例如拖动某个精灵,后面有长长的尾巴。cocos2dx中提供了这样的一个类,CCMotionStreak。OK,我们将配合上篇文章中讲到的粒子,来实现一个效果,直接上代码:

    cocos2d::CCParticleSystemQuad *particle;
        
        
        particle=CCParticleSystemQuad::create("Particle.plist");
        
        particle->setPosition(ccp(200, 200));
        
        this->addChild(particle, 1);
        
        cocos2d::CCMotionStreak *_streak;
        
        //第一个参数是渐隐的时间,第二个参数是间隐片断的大小,第三个参数是贴图的宽高,第四个参数是颜色,最后一个参数是贴图的路径
        _streak=CCMotionStreak::create(1, 16, 16, ccc3(255,255,0), "sprite.png");
        
        _streak->setPosition(ccp(200, 200));
        
        this->addChild(_streak, 1);
    

    重写touchmove事件:

    void HelloWorld::ccTouchesMoved(CCSet *touchs, CCEvent *event)
    {
    
        //获取触点指针容器中第一个元素
        CCSetIterator it=touchs->begin();
        //将其转化为触点信息
        CCTouch *touch=(CCTouch *)(*it);
        
        CCPoint touchLocation=touch->getLocation();
        
        
      //  touchLocation=CCDirector::sharedDirector()->convertToGL(touchLocation);
        
        
        
        particle->setPosition(ccp(touchLocation.x, touchLocation.y));
        
        _streak->setPosition(ccp(touchLocation.x, touchLocation.y));
    
    
    }
    

    OK,让我们看看效果:

     

  • 相关阅读:
    利用Cubieborad破解WiFi
    从零开始——Mysql备份还原数据库
    从零开始——Ubuntu系统安装redis和phpredis
    监控应用卡顿BlockCanary
    2.AS内存分析
    热修复原理
    MultiDex 原理
    APP启动时白屏优化及multidex优化
    线程池的简便记忆方法
    2.volatile和AtomicXX
  • 原文地址:https://www.cnblogs.com/henrendadi/p/3142945.html
Copyright © 2020-2023  润新知