gpt4 book ai didi

iphone - 如何使用cocos2d制作特定方向的箭头?

转载 作者:行者123 更新时间:2023-12-03 20:31:55 25 4
gpt4 key购买 nike

我想要两个物体排成一排,如下所示,并让一个物体从下方拍摄它们,如下所示

                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

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

谢谢

最佳答案

不需要多个图像......只需在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]];

关于iphone - 如何使用cocos2d制作特定方向的箭头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8089902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com