Avoid Node from moving erratically during a MoveTo action

I have a bottom menu with a slider(similar to Clash Royale and Golf Clash). In the bottom menu, I have to move the slider to the position where the click occurred. I have no issues with the movement, as I am using the generic MoveTo API as follows:

auto moveTo = MoveTo::create(0.2, Vec2(176.88, 57.02));
m_demoNode->runAction(moveTo);
m_childImageofDemoNode->setRotation(1.72);

However, during the movement, the node is exhibiting a behaviour - it is looking like it is jumping for a moment, which could possibly be explained due to the change in rotation, as the rotation changes from 0.0 to 1.72f. Is there any way I could fix this? A solution would be to limit the Y axis during movements, but I could not find any way to do it. Any help would be appreciated.

What OS? What device? Is it a low-end device? What Cocos version?

Using 3.17.2 with C++. Tested on an XCode simulator, and 2-3 Android devices(Note 9, and Moto G4 and G6). It’s not a device issue.
I have pinned down the issue - the rotation is changed before/after the MoveTo action, and the behaviour is related to that, and the change in Y axis position. I would not be able to keep the Y axis position the same as the base I have for the footer is a curved base.
Hence, I was wondering whether there’s any way to control coordinate threshold in Cocos2DX while using MoveTo.

And thank you so much for your reply!

Can you show me more code for creation and manipulation of m_demoNode and mChildImageOfDemoNode?

Of course!

    auto moveTo = MoveTo::create(0.2, Vec2(236.72, 53.33));
    m_demoNode->runAction(moveTo);
    m_childImageofDemoNode->setRotation(1.72);
    m_childImageofDemoNode->cocos2d::Node::setPosition(33.00, 3.26);

This is about it. If I keep the Y axis before moving and after moving the same and the rotation the same, the irregular movement does not occur. I am aware this is due to Cocos2DX design, but any workaround would be amazing :smiley:
And thanks again, slackmoehrle.

If you were referring to the creation, they are assigned with User Data coming in from Cocos Studio.

Darn, I wont be able to test this easily.

Perhaps run cocos new ... and create a simple MoveTo test to see if the erratic behavior is reproduced.

I hope I am clear with the question now. If I am not, kindly let me know and I will try my best to elucidate more!

I have tested that too. It’s not an erratic behaviour from the development point of view per se(Quite expected); but it’s an erratic behaviour from the functionality perspective. Let me explain it more in a very simple situation:

  1. I create a Node, with an Image View as its child. The Image View is at, let’s say (x,y).
  2. I click somewhere in the screen, and I want the node(and automatically the child) to move to (w,z) - using MoveTo. However, while y != z, the node looks to go up/down a little bit depending on the difference between y and z. My question is - whether there’s any way simple to manipulate the automatic movement by the MoveTo API.

Once again, thank you :smiley:

I can try to look at this later on this week. I am really busy these next few days at least.

1 Like

How I fixed it:

I created Animations from Cocos Studio. The same can be done from Cocos Creator as well. I re-used 8 different animations for 120 scenarios, via writing a code to reverse and change speed of the action timelines. MoveTo isn’t the way to go if you are creating a footer which has a curved based where the value of y is not uniform. If y is uniform, a simple MoveTo and proper parent-child relationships will fix this issue.

1 Like