moving CCSprit to the left causing strange movement all other direction are working

て烟熏妆下的殇ゞ 提交于 2019-12-12 02:29:34

问题


i try to move simple CCNode with CCSprit as member to the left side and it give me strange result , all the other dirctions working fine that is right , up , down only left give me problem the sprit is moving way out of the screen . here are the functions i have
they are called on ccTouchMoved
the job is to take the near sprite (Gem* other ) and replace with the current

//THIS IS THE PROBLEMATIC FUNCTION 
void Gem::setGemPositionAnimationLeft(Gem* other,bool bMatch)
{
    CCLOG("setGemPositionAnimationLeft");
    CCPoint OrigGemPoint  = getGemPos();
    CCPoint otherOrigGemPoint =  other->getGemPos();



    CCMoveTo *otherMoveRight = CCMoveTo::create(0.3f,OrigGemPoint);
    CCMoveTo *otherMoveLeft = CCMoveTo::create(0.3f,otherOrigGemPoint);
    CCMoveTo *origMoveRight = CCMoveTo::create(0.3f,OrigGemPoint);
    CCMoveTo *origMoveLeft = CCMoveTo::create(0.3f,otherOrigGemPoint);

    CCSequence*  otherSequenceActionRightAndLeft = CCSequence::create(otherMoveRight,otherMoveLeft, NULL);
    other->mySprite->runAction(otherSequenceActionRightAndLeft);


    CCSequence*  origSequenceActionLeftAndRight = CCSequence::create(origMoveLeft,origMoveRight,NULL);
    mySprite->runAction(origSequenceActionLeftAndRight);
}

void Gem::setGemPositionAnimationRight(Gem* other,bool bMatch)
{
    CCLOG("setGemPositionAnimationRight");
    CCPoint OrigGemPoint  = getGemPos();
    CCPoint otherOrigGemPoint =  other->getGemPos();



    CCMoveTo *otherMoveLeft = CCMoveTo::create(0.3f,OrigGemPoint);
    CCMoveTo *otherMoveRight = CCMoveTo::create(0.3f,otherOrigGemPoint);
    CCMoveTo *origMoveRight = CCMoveTo::create(0.3f,otherOrigGemPoint);
    CCMoveTo *origMoveLeft = CCMoveTo::create(0.3f,OrigGemPoint);

    CCSequence*  otherSequenceActionLeftAndRight = CCSequence::create(otherMoveLeft,otherMoveRight, NULL);
    other->mySprite->runAction(otherSequenceActionLeftAndRight);


    CCSequence*  origSequenceActionRightAndLeft = CCSequence::create(origMoveRight,origMoveLeft,NULL);
    mySprite->runAction(origSequenceActionRightAndLeft);
}

void Gem::setGemPositionAnimationUp(Gem* other,bool bMatch)
{

    CCLOG("setGemPositionAnimationUp");
    CCPoint upperOrigGemPoint  = getGemPos();
    CCPoint otherOrigGemPoint =  other->getGemPos();



    CCMoveTo *otherMoveDown = CCMoveTo::create(0.3f,upperOrigGemPoint);
    CCMoveTo *moveDown = CCMoveTo::create(0.3f,upperOrigGemPoint);
    CCMoveTo *moveUp = CCMoveTo::create(0.3f,otherOrigGemPoint);
    CCMoveTo *otherMoveUp = CCMoveTo::create(0.3f,otherOrigGemPoint);

    CCSequence*  SequenceActionUpAndDown = CCSequence::create(moveDown,moveUp, NULL);
    other->mySprite->runAction(SequenceActionUpAndDown);
    // upper gem move down action
    CCSequence*  SequenceActionDownAndUp = CCSequence::create( otherMoveUp,otherMoveDown,NULL);
    mySprite->runAction(SequenceActionDownAndUp);

}

void Gem::setGemPositionAnimationDown(Gem* other,bool bMatch)
{
      CCLOG("setGemPositionAnimationDown");

      CCPoint upperOrigGemPoint  = getGemPos();
      //CCLOG("Gem %s %s upperOrigGemPoint! x:%f ,y:%f",getImageName().c_str(),getGemId().c_str(),upperOrigGemPoint.x,upperOrigGemPoint.y);
      //the down gem pos , that the upper gem suppose to go when dragged down
      CCPoint otherOrigGemPoint =  other->getGemPos();
      //CCLOG("Gem %s %s moveToPoint! x:%f ,y:%f",other->getImageName().c_str(),other->getGemId().c_str(),moveToPoint.x,moveToPoint.y);


      //down gem move up action    
      CCMoveTo *otherMoveUp = CCMoveTo::create(0.3f,upperOrigGemPoint);
      CCMoveTo *moveUp = CCMoveTo::create(0.3f,upperOrigGemPoint);
      CCMoveTo *moveDown = CCMoveTo::create(0.3f,otherOrigGemPoint);
      CCMoveTo *otherMoveDown = CCMoveTo::create(0.3f,otherOrigGemPoint);


      CCSequence*  SequenceActionUpAndDown = CCSequence::create(otherMoveUp,otherMoveDown, NULL);
      other->mySprite->runAction(SequenceActionUpAndDown);

      // upper gem move down action    
      CCSequence*  SequenceActionDownAndUp = CCSequence::create( moveDown,moveUp, NULL);
      mySprite->runAction(SequenceActionDownAndUp);

}

来源:https://stackoverflow.com/questions/17879355/moving-ccsprit-to-the-left-causing-strange-movement-all-other-direction-are-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!