2

我想要一行中的两个对象,如下所示,并且有一个对象从下方拍摄它们,如下所示

                0 0 0 0 0 0 




                     0

较低的总是在它的位置上,并且会射到上面,我想做箭头,因为用户会在 iPhone 的屏幕上移动它的手指,如下所示

                 0 0 0 0 0 0 

                   \
                    \
                     \
                      0

如果移动手指然后

                  0 0 0 0 0 0                             
                      |
                      |
                      | 
                      0

在将屏幕上的一根手指更向右移动时,箭头应分别移动为

                  0 0 0 0 0 0                             
                          /
                         /
                        /
                      0

我该如何实现这个逻辑,我应该有多个数组图像并根据角度使用它们,或者什么,但我想要它的准确性。

谢谢

4

3 回答 3

4

不需要多个图像....只需在 touchesMoved 方法中旋转箭头图像

试试那个代码。

UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];


// Set up initial location of projectile
CGSize winSize = [[CCDirector sharedDirector] winSize];

// Rotate player to face shooting direction
CGPoint shootVector = ccpSub(location, sprite.position);
CGFloat shootAngle = ccpToAngle(shootVector);
CGFloat cocosAngle = CC_RADIANS_TO_DEGREES(-1 * shootAngle);

CGFloat curAngle = _player.rotation;
CGFloat rotateDiff = cocosAngle - curAngle;    
if (rotateDiff > 180)
    rotateDiff -= 360;
if (rotateDiff < -180)
    rotateDiff += 360;    

CGFloat rotateSpeed = 360; // degrees per second
CGFloat rotateDuration = fabs(rotateDiff / rotateSpeed);

[yoursprite runAction:[CCSequence actions:
                    [CCRotateTo actionWithDuration:rotateDuration angle:cocosAngle],
                    [CCCallFunc actionWithTarget:self selector:@selector(finishShoot)],
                    nil]];
于 2011-11-11T05:34:12.313 回答
1

检查以下链接以在触摸移动时旋转图像

在这里你必须限制你想要的角度之间的角度

旋转图像

于 2011-11-11T05:46:37.023 回答
0

正如 Anshul 和 Nikhil 所说,旋转箭头应该足以解决您的问题。

另外请注意,您可能需要创建箭头精灵,并在其底部中心( 0.5, 0.5 )设置一个锚点,以避免注意到您的箭头左右移动,具体取决于您的设置。

最好的,

于 2011-11-11T08:00:38.390 回答