MoveTo or JumpTo using update function

  • pabitrapadhy
    Likes 1

    Problem Description

    Hi,
    I am trying to achieve the same MoveTo action and JumpTo action but without using the Actions in cocos2d-x.

    The reason for this is my game has wind effect and I need to alter the end location.

    I’ve been through the source code of JumpBy update() and MoveBy update(), but i am not clear how do they do it.

    I will give you an instance of what i want – 

    i know the start point and end point, (say start point contains a sprit and end point is the crosshair where i need to throw the target in trajectory path)

    time from the start point to the crosshari is 1 second.

    how can I achieve this.. !!
    please help me.

    Thank you in advance.

  • Sonar Systems admin
    Likes 0

    Have you tried using actions but with easing as that may be able to replicate the wind effect when moving objects.

     

    Kind regards

    Sonar Team


    This reply has been verified.
  • pabitrapadhy
    Likes 0

    nope, that’s not what would do.

    actually in my game I have a left to right / right to left wind effect with certain velocity

    say with wind effect enabled each time the x value will be added with an offset of 1 in the update funciton itself.
    I need to understand the logic behind JumpBy update function and how they do it with time.
    when I use Jump by – i have the start and endpos so, i can calculate the height and the x difference

    when i try it with JumpBy it works fine, but i am failing to understand the logic, that how it works.
    could you please help me.. !!


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    MoveTo is easier to get around but JumpTo has a lot to it.


    This reply has been verified.
  • pabitrapadhy
    Likes 0

    yes.. basically i am trying to understand this piece of code.
    in some easier terms

     

    void JumpBy::update(float t)
      {
      // parabolic jump (since v0.8.2)
      if (_target)
      {
      float frac = fmodf( t * _jumps, 1.0f );
      float y = _height * 4 * frac * (1 - frac);
      y += _delta.y * t;
       
      float x = _delta.x * t;
      #if CC_ENABLE_STACKABLE_ACTIONS
      Vec2 currentPos = _target->getPosition();
       
      Vec2 diff = currentPos - _previousPos;
      _startPosition = diff + _startPosition;
       
      Vec2 newPos = _startPosition + Vec2(x,y);
      _target->setPosition(newPos);
       
      _previousPos = newPos;
      #else
      _target->setPosition(_startPosition + Vec2(x,y));
      #endif // !CC_ENABLE_STACKABLE_ACTIONS
      }
      }

    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    There is a reason it’s done for you as realistic jumping isn’t easy but you may be able to replicate what you want with a mixture of normal actions with easing inside a sequence.


    This reply has been verified.
  • pabitrapadhy
    Likes 1

    Hi

    Thank you for your help.
    I got a forum reply from @mannewalis

    greatly explained by him. Please do refer if anyone is seeking more knoledge. :)
    here’s the link – http://discuss.cocos2d-x.org/t/explain-update-of-jumpby/20124/9?u=pabitrapadhy

    also.. I want to thank SonarSystem for their quick and helpful response. :)


    This reply has been verified.
  • Sonar Systems admin
    Likes 0

    Your welcome :D


    This reply has been verified.

Login to reply