从Delphi开始学Cocos2dx-3.0[12]:可变速度

来源:互联网 发布:vantagepoint软件下载 编辑:程序博客网 时间:2024/06/05 03:50

cocos里面的速度  还不是普通的意义上的速度

大概分成3种 , 

1, 先加速再减速 In

2, 先减速再加速 Out

3, 先减速再加速然后还减速 InOut


为了测试三个的速度. 这回必须要弄3张图片上去了.

    // 添加一张精灵图片    auto sprite1 = TSprite::create("ball.png");    // 设置位置到正中间    sprite1->setPosition(TPoint(100.0f, 100.0f));    // 添加到Helloworld图层    this->addChild(sprite1, 0, 1000);    auto sprite2 = TSprite::create("ball.png");    sprite2->setPosition(TPoint(100.0f, 300.0f));    this->addChild(sprite2, 0, 1001);    auto sprite3 = TSprite::create("ball3.png");    sprite3->setPosition(TPoint(100.0f, 500.0f));    this->addChild(sprite3, 0, 1002);        return true;


bool THelloWorld::onTouchBegan(TTouch* touch, TEvent* event){auto sprite1 =  (TSprite*)(this->getChildByTag(1000));  auto sprite2 =  (TSprite*)(this->getChildByTag(1001));  auto sprite3 =  (TSprite*)(this->getChildByTag(1002));  static int nTempIdx = 0;switch (nTempIdx++){case 0: // 大家一起往右移动{sprite1->runAction(TEaseIn::create(TMoveBy::create(1, TPoint(600.0f, 0.0f)),2.0f));sprite2->runAction(TEaseOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f)),2.0f));sprite3->runAction(TEaseInOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f)),2.0f));} break;case 1: // 大家一起往左移动{sprite1->runAction(TEaseIn::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f)),0.5f));sprite2->runAction(TEaseOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f)),0.5f));sprite3->runAction(TEaseInOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f)),0.5f));} break;case 2: // 大家一起往右移动{sprite1->runAction(TEaseSineIn::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite2->runAction(TEaseSineOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite3->runAction(TEaseSineInOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));} break;case 3: // 大家一起往左移动{sprite1->runAction(TEaseSineIn::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite2->runAction(TEaseSineOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite3->runAction(TEaseSineInOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));} break;case 4: // 大家一起往右移动{sprite1->runAction(TEaseBackIn::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite2->runAction(TEaseBackOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite3->runAction(TEaseBackInOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));} break;case 5: // 大家一起往左移动{sprite1->runAction(TEaseBackIn::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite2->runAction(TEaseBackOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite3->runAction(TEaseBackInOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));} break;case 6: // 大家一起往右移动{sprite1->runAction(TEaseExponentialIn::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite2->runAction(TEaseExponentialOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite3->runAction(TEaseExponentialInOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));} break;case 7: // 大家一起往左移动{sprite1->runAction(TEaseExponentialIn::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite2->runAction(TEaseExponentialOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite3->runAction(TEaseExponentialInOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));} break;case 8: // 大家一起往右移动{sprite1->runAction(TEaseBounceIn::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite2->runAction(TEaseBounceOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite3->runAction(TEaseBounceInOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));} break;case 9: // 大家一起往左移动{sprite1->runAction(TEaseBounceIn::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite2->runAction(TEaseBounceOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite3->runAction(TEaseBounceInOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));} break;case 10: // 大家一起往右移动{sprite1->runAction(TEaseElasticIn::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite2->runAction(TEaseElasticOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));sprite3->runAction(TEaseElasticInOut::create(TMoveBy::create(1, TPoint(600.0f, 0.0f))));} break;case 11: // 大家一起往左移动{sprite1->runAction(TEaseElasticIn::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite2->runAction(TEaseElasticOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));sprite3->runAction(TEaseElasticInOut::create(TMoveBy::create(1, TPoint(-600.0f, 0.0f))));} break;default: {sprite1->runAction(TPlace::create(TPoint(100.0f, 100.0f)));sprite2->runAction(TPlace::create(TPoint(100.0f, 300.0f)));sprite3->runAction(TPlace::create(TPoint(100.0f, 500.0f)));nTempIdx = 0;}}    CCLOG("THelloWorld::onTouchBegan id = %d, x = %f, y = %f", touch->getID(), touch->getLocation().x, touch->getLocation().y);    return true;}


0 0