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) );
    }

  • 相关阅读:
    Linux -- 查看是否安装了指定的包
    linux -- 部署java服务器(1) linux安装jdk
    spring boot -- 接收文件接口
    vue3 --相对于vue2的改变T1档次
    243交换输出
    24416进制的简单运算
    7街区最短路径问题
    206矩形的个数
    33蛇形填数
    273字母小游戏
  • 原文地址:https://www.cnblogs.com/newlist/p/3213598.html
Copyright © 2011-2022 走看看