gpt4 book ai didi

iphone - UIGestureRecognizer不会旋转 Sprite - Cocos2d

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

有人知道为什么它不会旋转 Sprite 吗?

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];

CGPoint center = CGPointMake(CGRectGetMidX([[touch view] bounds]), CGRectGetMidY([[touch view] bounds]));

CGPoint firstLocation = [touch previousLocationInView:[touch view]];
CGPoint location = [touch locationInView:[touch view]];

CGPoint currentTouchPoint = [[CCDirector sharedDirector] convertToGL:location];
CGPoint previousTouchPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];

CGPoint line2Start = currentTouchPoint;
CGPoint line1Start = previousTouchPoint;
CGPoint line2End = CGPointMake(center.x + (center.x - line2Start.x), center.y + (center.y - line2Start.y));
CGPoint line1End = CGPointMake(center.x + (center.x - line1Start.x), center.y + (center.y - line1Start.y));

CGFloat a = line1End.x - line1Start.x;
CGFloat b = line1End.y - line1Start.y;
CGFloat c = line2End.x - line2Start.x;
CGFloat d = line2End.y - line2Start.y;

CGFloat line1Slope = (line1End.y - line1Start.y) / (line1End.x - line1Start.x);
CGFloat line2Slope = (line2End.y - line2Start.y) / (line2End.x - line2Start.x);

CGFloat degs = acosf(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));

CGFloat angleInRadians = (line2Slope > line1Slope) ? degs : -degs;

[g setRotation:angleInRadians];
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
UIGestureRecognizer *recognizer;
[recognizer setState:UIGestureRecognizerStateEnded];
}

G是[g setRotation:angleInRadians]中的 Sprite ;

然后,当我添加这个时

[[touch view] setTransform:CGAffineTransformRotate([[touch view] transform], [grinder rotation])];

它旋转整个场景!请问有什么帮助吗?

谢谢!

最佳答案

哥们

下面是 ui-kit 的链接,但它也适用于 cocos2d你需要照顾好协调系统

1)对于cocos2d,原点是左下角

2)对于UIKit,原点是左上角

"Rotate image by Dragging"

希望这对您有帮助祝你好运

关于iphone - UIGestureRecognizer不会旋转 Sprite - Cocos2d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6259800/

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