C++ 向左移动CCSprit导致奇怪的移动所有其他方向都在工作
我尝试将带有CCSprit的简单CCNode移动到左侧,它会给我奇怪的结果,所有其他方向都正常工作,即向右、向上、向下,只有向左给我带来问题sprit正在从屏幕中移出。以下是我拥有的功能C++ 向左移动CCSprit导致奇怪的移动所有其他方向都在工作,c++,cocos2d-x,C++,Cocos2d X,我尝试将带有CCSprit的简单CCNode移动到左侧,它会给我奇怪的结果,所有其他方向都正常工作,即向右、向上、向下,只有向左给我带来问题sprit正在从屏幕中移出。以下是我拥有的功能 他们在CCT上被调用 任务是将近精灵(Gem*other)替换为当前精灵 //THIS IS THE PROBLEMATIC FUNCTION void Gem::setGemPositionAnimationLeft(Gem* other,bool bMatch) { CCLOG("setGemPo
他们在CCT上被调用
任务是将近精灵(Gem*other)替换为当前精灵
//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);
}
确保没有“移动”操作与其他操作同时运行。要确认这是否是您遇到的问题,请在运行“向左移动”操作或序列之前停止所有操作谢谢!这有帮助!你能解释一下原因吗?因为一个移动动作抵消了另一个移动动作的位置变化,所以它们不是为了配合而设计的(在cocos2d iphone 2.1中,你可以使用ccConfig标志来改变这种行为)