increasing the character speed in real-time

Cocos2d-x v3
  • pabitrapadhy
    Likes 0

    Problem Description

    Hello there,
    I have code like this – 

    // move action
        int maxFloors = DataManager::getInstance()->_floorCount;
        this->_liftSpeed = DataManager::getInstance()->_liftSpeed;
        
        auto move = MoveBy::create(fabs(steps * this->_liftSpeed), Vec2(0, (spaceBuilding->getContentSize().height/maxFloors * steps)));
        auto liftFreeCB = CallFunc::create( [&, floorNum, requestedLevelLabel] () {
            
            Size visibleSize = Director::getInstance()->getVisibleSize();
            Vec2 origin = Director::getInstance()->getVisibleOrigin();
            
            // set the lift to free
            this->_isLiftBusy = false;
            CCLOG("LIFT FREE");
            
            // set the current floor number for the lift
            this->_currFloor = floorNum;
    
            // something's going on.......
    });

    Now, when I change the speed of the sprite, and by that time if it is moving, it will not reflect the new speed.
    because for MoveBy action is already running.

    If I need to reflect the speed instantly, how could I do that. ?
     

  • Sonar Systems admin
    Likes 0

    Stop the action.

Login to reply