我想用 CCMove 移动身体我正在使用下面的代码它就像一个平板我想将它从 1px 移动到 100px 然后从 100px 移动到 1px 如果我只从 1x 移动到 100px 它工作正常但它的行为出乎意料当我搬回来
void MovableBlock::update(float dt) {
b2Vec2 position;
if(isForward) {
positionAnimationImg = ccpAdd(positionAnimationImg, animatableImage->getPosition());
position = point_to_vec(ccp(this->getPositionX()+positionAnimationImg.x,this->getPositionY()));
}
else {
positionAnimationImg = ccpSub(positionAnimationImg, animatableImage->getPosition());
position = point_to_vec(ccp(positionAnimationImg.x-this->getPositionX(),this->getPositionY()));
}
CCLog("%f:%f",this->getBody()->GetTransform().p.x,position.y);
//CCLog("position>> %f:%f",position.x,position.y);
this->getBody()->SetTransform(b2Vec2(position.x,
position.y),
this->getBody()->GetAngle());
animatableImage->setPosition(CCPointZero);
}