Get position of a sprite when moveTo action

Is it possible to get current position of a sprite when we make moveTo action? I can only get start position and finish position of sprite. I need current.
Is it possible?
If not will cocos2d support it in some new version?

sprite->getPosition(); ??

it was weird, my mistake, it does work :wink: earlier I was getting like start position and than end position. But I think it was my game logic…

The position of the sprite will change during the duration of the MoveTo action. When I need to keep track of the position of sprites during the action, I simply use schedule an update function to keep track by using getPosition()

yeah I do that, but the position seems not to be accurate. Like the visible sprite is a 20px in the wrong place…

Yah, I understand that the accuracy might be off. I suspect that at the beginning of each frame, the engine would render the updated stats first, perform the actions, then call the update function. As such, the position returned is the position for the next frame. Please correct me if I am wrong on this.

If I require more accuracy, I normally would move my sprites in the update function instead.

you may be right, I didn’t check that… but isn’t moving the sprite using update in pure js is just slower and worse performance?

I do not see how it can be slower. MoveTo or MoveBy actions are only there for convenience. In fact, I believe that both approaches should have similar performance. The only difference is when the code is executed.

well in documentation is written I think that all the actions are done by c++ code, so it should be faster…

If you are using JS, then it might be the case. If you are using C++, then it does not even matter actually. From what I know, even if you use JS, the difference in performance should be very minimal, unless you are very particular about the nanoseconds…

The movement is using delta time, so it should be the same no matter what the frame rate is.

well first of all, getting width of a sprite when it’s scaled is not good idea as we getting width of not scaled sprite.
Secondly moving sprite using update loop and js is very precise. Using moveto and checking x position to collide is not precise, especially when you’re moving sprite fast. So there is somewhere some bug in moveto actions (probably in all actions) so unless someone fix it using actions just make no sense for me. Which I think is a bug.
Action position isn’t refreshed fast enough.

It’s weird because sprite x position is like 280px and collision is on 290px and actual sprite is drown at 310px. So I think someone from cocos2d team should look at it and prepare some fix…

so I think I will have to rewrite it in JS than… no attention from cocos2d …

ok I checked this. so delta times are corrects all updates function are called with good 1/60 frame update. The problem is as you wrote when I’m moving object fast we move it like for example 25px every frame. So my collision detects that the objects collide on the new position which is not redrawn yet. So if objects overlap each other with 1px than we have a gap of 24px + 25px. also I was getting width without scaled object so there was additional gap. So the slower the movement the less gap. But I’m still thinking how to make it more precise…