zoukankan      html  css  js  c++  java
  • 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,让我们看看效果:

     

  • 相关阅读:
    个人最终总结
    电梯调度的改进
    电梯调度程序
    读程序的修改
    对wordcount单词字母部分的修改
    wordcount
    读程序
    单元测试
    Microsoft Visual Studio 2013安装及试用
    附加题(二)——沈航软件工程期末附加作业
  • 原文地址:https://www.cnblogs.com/henrendadi/p/3142945.html
Copyright © 2011-2022 走看看