zoukankan      html  css  js  c++  java
  • CCMotionStreak(一)

    void MotionStreakTest1::onEnter()
    {
        MotionStreakTest::onEnter();
    
        CCSize s = CCDirector::sharedDirector()->getWinSize();
      
        // the root object just rotates around
        m_root = CCSprite::create(s_pPathR1);
        addChild(m_root, 1);
        m_root->setPosition(ccp(s.width/2, s.height/2));
      
        // the target object is offset from root, and the streak is moved to follow it
        m_target = CCSprite::create(s_pPathR1);
        m_root->addChild(m_target);
        m_target->setPosition(ccp(s.width/4, 0));
    
        // create the streak object and add it to the scene
        streak = CCMotionStreak::create(2, 3, 32, ccGREEN, s_streak);
        addChild(streak);
        // schedule an update on each frame so we can syncronize the streak with the target
        schedule(schedule_selector(MotionStreakTest1::onUpdate));
      
        CCActionInterval* a1 = CCRotateBy::create(2, 360);
    
        CCAction* action1 = CCRepeatForever::create(a1);
        CCActionInterval* motion = CCMoveBy::create(2, ccp(100,0) );
        m_root->runAction( CCRepeatForever::create((CCActionInterval*)(CCSequence::create(motion, motion->reverse(), NULL)) ) );
        m_root->runAction( action1 );
    //最后的颜色会跟背景色一致,这样就达到逐渐消失的效果
        CCActionInterval *colorAction = CCRepeatForever::create((CCActionInterval *)CCSequence::create(
            CCTintTo::create(0.2f, 255, 0, 0),
            CCTintTo::create(0.2f, 0, 255, 0),
            CCTintTo::create(0.2f, 0, 0, 255),
            CCTintTo::create(0.2f, 0, 255, 255),
            CCTintTo::create(0.2f, 255, 255, 0),
            CCTintTo::create(0.2f, 255, 0, 255),
            CCTintTo::create(0.2f, 255, 255, 255),
            NULL));
    
        streak->runAction(colorAction);
    }
    
    void MotionStreakTest1::onUpdate(float delta)
    {
    //先获取精灵m_target左上角的坐标,然后赋值给streak,m_target的坐标一直在变化
        streak->setPosition( m_target->convertToWorldSpace(CCPointZero) );
    }

  • 相关阅读:
    生成格雷码 转自leetcode
    webstorm注册码 永久有效!!!(亲测有效)
    Myeclipse或者eclipse太卡
    对封装的再次理解(容器)
    几个好的参考的网站
    将json字符串转为json对象,从对象中取需要的数据
    ElementUI学习笔记
    Oracle的case when 和decode
    20190807更新数据相关笔记
    oracle未查找到任何数据问题
  • 原文地址:https://www.cnblogs.com/newlist/p/3213598.html
Copyright © 2011-2022 走看看