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

  • <legend id='KSGDK'><style id='KSGDK'><dir id='KSGDK'><q id='KSGDK'></q></dir></style></legend>

      1. <small id='KSGDK'></small><noframes id='KSGDK'>

        在 Cocos2d-iPhone 中围绕圆周移动精灵

        Moving a sprite around the circumference of a circle in Cocos2d-iPhone(在 Cocos2d-iPhone 中围绕圆周移动精灵)
          <tbody id='pxci9'></tbody>

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

            <bdo id='pxci9'></bdo><ul id='pxci9'></ul>

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

                • 本文介绍了在 Cocos2d-iPhone 中围绕圆周移动精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Cocos2d 的新手.我查看了文档,与使用基本的 Iphone 类(如 UIAnimation 等)相比,它看起来非常简单.

                  I am new to Cocos2d. I have taken a look at the documentation at it looks pretty simple compared to what you need to do using basic Iphone classes such as UIAnimation etc.

                  我想围绕其圆周的圆心平滑移动精灵(例如鸟、飞机或汽车),以便精灵也相应地旋转.

                  I want to move a Sprite (eg. Bird, Plane or Car) around the center of a circle around its circumference, smoothly so that even the sprite rotates accordingly.

                  这在 Cocos2d 中怎么可能?如果有人可以发布一些基本代码,那将非常有帮助.

                  How is this possible in Cocos2d? It would be very helpful if someone can post some basic code.

                  谢谢.

                  推荐答案

                  一种方法是安排一个选择器定期运行,当它被调用时,将你的精灵移动到圆圈上.

                  One way to do it is to schedule a selector to run periodically, and when it's called, move your sprite over the circle.

                  为此,您可以查看 CGPointExtension.m 中的函数.特别是,您可以使用 ccpForAngleccpMultccpAdd.你可以这样做:

                  To do that, you can take a look at the functions at CGPointExtension.m. In particular, you can use ccpForAngle, ccpMult, and ccpAdd. You could do something like this:

                  // Assume the class is a subclass of CCNode, and has the following properties:
                  // radius: the radius of the circle you want the sprite to move over.
                  // circleCenter: the center of the circle
                  // currentAngle: the angle where the sprite currently is
                  - (void)tick {
                      float anglePerTick = 0.1; // this will determine your speed
                      currentAngle += anglePerTick;  
                      self.position = ccpAdd(ccpMult(ccpForAngle(currentAngle), radius)),
                                             circleCenter);
                      self.rotation = currentAngle * 180 / M_PI; // Convert from radians to degrees
                  }
                  

                  这种方法的主要问题是您将角速度设置为常数,因此如果圆圈变大,精灵将在每个刻度上移动的距离"会增加,并可能导致闪烁.

                  The main problem with this approach is that you are setting the angular velociy as a constant, so if the circle gets bigger, the "distance" the sprite will travel on each tick will increase, and may lead to flickering.

                  这篇关于在 Cocos2d-iPhone 中围绕圆周移动精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Resume game cocos2d(恢复游戏 cocos2d)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
                  <tfoot id='3ruCy'></tfoot>

                      <tbody id='3ruCy'></tbody>
                    <legend id='3ruCy'><style id='3ruCy'><dir id='3ruCy'><q id='3ruCy'></q></dir></style></legend>
                      <i id='3ruCy'><tr id='3ruCy'><dt id='3ruCy'><q id='3ruCy'><span id='3ruCy'><b id='3ruCy'><form id='3ruCy'><ins id='3ruCy'></ins><ul id='3ruCy'></ul><sub id='3ruCy'></sub></form><legend id='3ruCy'></legend><bdo id='3ruCy'><pre id='3ruCy'><center id='3ruCy'></center></pre></bdo></b><th id='3ruCy'></th></span></q></dt></tr></i><div id='3ruCy'><tfoot id='3ruCy'></tfoot><dl id='3ruCy'><fieldset id='3ruCy'></fieldset></dl></div>
                        <bdo id='3ruCy'></bdo><ul id='3ruCy'></ul>
                      • <small id='3ruCy'></small><noframes id='3ruCy'>