I need move a sprite repeat forever, and I need do something between every step. So I using bellow code.
GameLayer::move() { MoveBy *move = MoveBy::create(0.2, Point(16,0)); Sequence *seq = Sequence::create(move, CallFunc::create(CC_CALLBACK_0(GameLayer::oneStep, this)), NULL); Action *moveAction = RepeatForever::create(seq); mSprite->runAction(moveAction); } GameLayer::oneStep() { Point pos = mSprite->getPosition(); log("current position[%f,%f]", pos.x, pos.y); }
log:
current position[392.000000,136.000000]
current position[408.079895,136.000000] (right value [408,136])
current position[425.767242,136.000000] (right value [424,136])
current position[440.077759,136.000000] (right value [440,136])
But the MoveBy action seems has deviation with repeatForever.
The position of mSprite should always move by offset(16,0), but there always a bit more or little.The deviation will intolerable as time elasped.
If I force set mSprite to the right position on oneStep function, the action stumbled…
Any suguesstion to solve this problem?