<legend id='bxMod'><style id='bxMod'><dir id='bxMod'><q id='bxMod'></q></dir></style></legend>

    <small id='bxMod'></small><noframes id='bxMod'>

  • <i id='bxMod'><tr id='bxMod'><dt id='bxMod'><q id='bxMod'><span id='bxMod'><b id='bxMod'><form id='bxMod'><ins id='bxMod'></ins><ul id='bxMod'></ul><sub id='bxMod'></sub></form><legend id='bxMod'></legend><bdo id='bxMod'><pre id='bxMod'><center id='bxMod'></center></pre></bdo></b><th id='bxMod'></th></span></q></dt></tr></i><div id='bxMod'><tfoot id='bxMod'></tfoot><dl id='bxMod'><fieldset id='bxMod'></fieldset></dl></div>
        • <bdo id='bxMod'></bdo><ul id='bxMod'></ul>

        <tfoot id='bxMod'></tfoot>

        Cocos2d - 以正弦波运动将精灵从 A 点移动到 B 点

        时间:2024-08-11
          <tbody id='54y74'></tbody>

        • <i id='54y74'><tr id='54y74'><dt id='54y74'><q id='54y74'><span id='54y74'><b id='54y74'><form id='54y74'><ins id='54y74'></ins><ul id='54y74'></ul><sub id='54y74'></sub></form><legend id='54y74'></legend><bdo id='54y74'><pre id='54y74'><center id='54y74'></center></pre></bdo></b><th id='54y74'></th></span></q></dt></tr></i><div id='54y74'><tfoot id='54y74'></tfoot><dl id='54y74'><fieldset id='54y74'></fieldset></dl></div>
            <bdo id='54y74'></bdo><ul id='54y74'></ul>

            1. <legend id='54y74'><style id='54y74'><dir id='54y74'><q id='54y74'></q></dir></style></legend>
              • <tfoot id='54y74'></tfoot>

                  <small id='54y74'></small><noframes id='54y74'>

                  本文介绍了Cocos2d - 以正弦波运动将精灵从 A 点移动到 B 点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  What would be the best way to do this? I see the CCEaseSineInOut action but it doesn't look like that could be used to do this.

                  I need to move from one side of the screen to the other. The sprite should move in a sine-wave pattern across the screen.

                  解决方案

                  I always like to have complete control over CCNode motion. I only use CCActions to do very basic things. While your case sounds simple enough to possibly do with CCActions, I will show you how to move a CCNode according to any function over time. You can also change scale, color, opacity, rotation, and even anchor point with the same technique.

                  @interface SomeLayer : CCLayer
                  {
                      CCNode *nodeToMove;
                      float t; // time elapsed
                  }
                  @end
                  
                  @implementation SomeLayer
                  
                  // Assumes nodeToMove has been created somewhere else
                  -(void)startAction
                  {
                      t = 0;
                  
                      // updateNodeProperties: gets called at the framerate
                      // The exact time between calls is passed to the selector
                      [self schedule:@selector(updateNodeProperties:)];
                  }
                  
                  -(void)updateNodeProperties:(ccTime)dt
                  {
                      t += dt;
                  
                      // Option 1: Update properties "differentially"
                      CGPoint velocity = ccp( Vx(t), Vy(t) ); // You have to provide Vx(t), and Vy(t)
                      nodeToMove.position = ccpAdd(nodeToMove.position, ccpMult(velocity, dt));
                      nodeToMove.rotation = ...
                      nodeToMove.scale = ...
                      ...
                  
                      // Option 2: Update properties non-differentially
                      nodeToMove.position = ccp( x(t), y(t) ); // You have to provide x(t) and y(t)
                      nodeToMove.rotation = ...
                      nodeToMove.scale = ...
                      ...
                  
                     // In either case, you may want to stop the action if some condition is met
                     // i.e.)
                     if(nodeToMove.position.x > [[CCDirector sharedDirector] winSize].width){
                         [self unschedule:@selector(updateNodeProperties:)];
                         // Perhaps you also want to call some other method now
                         [self callToSomeMethod];
                     }
                  }
                  
                  @end
                  

                  For your specific problem, you could use Option 2 with x(t) = k * t + c, and y(t) = A * sin(w * t) + d.

                  Math note #1: x(t) and y(t) are called position parameterizations. Vx(t) and Vy(t) are velocity parameterizations.

                  Math note #2: If you have studied calculus, it will be readily apparent that Option 2 prevents accumulation of positional errors over time (especially for low framerates). When possible, use Option 2. However, it is often easier to use Option 1 when accuracy is not a concern or when user input is actively changing the parameterizations.

                  There are many advantages to using CCActions. They handle calling other functions at specific times for you. They are kept track of so that you can easily pause them and restart them, or count them.

                  But when you really need to manage nodes generally, this is the way to do it. For complex or intricate formulas for position, for example, it is much easier to change the parameterizations than to figure out how to implement that parameterization in CCActions.

                  这篇关于Cocos2d - 以正弦波运动将精灵从 A 点移动到 B 点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:调用插页式 iAd 只能使用一次 下一篇:cocos2d 动画后自动删除精灵

                  相关文章

                  1. <i id='tksRt'><tr id='tksRt'><dt id='tksRt'><q id='tksRt'><span id='tksRt'><b id='tksRt'><form id='tksRt'><ins id='tksRt'></ins><ul id='tksRt'></ul><sub id='tksRt'></sub></form><legend id='tksRt'></legend><bdo id='tksRt'><pre id='tksRt'><center id='tksRt'></center></pre></bdo></b><th id='tksRt'></th></span></q></dt></tr></i><div id='tksRt'><tfoot id='tksRt'></tfoot><dl id='tksRt'><fieldset id='tksRt'></fieldset></dl></div>

                      • <bdo id='tksRt'></bdo><ul id='tksRt'></ul>

                      <small id='tksRt'></small><noframes id='tksRt'>

                      <tfoot id='tksRt'></tfoot>
                      <legend id='tksRt'><style id='tksRt'><dir id='tksRt'><q id='tksRt'></q></dir></style></legend>