有沒有人有更好的方法來用一個手指旋轉雪碧?我的問題是我不能讓精靈在完全旋轉兩次後停止旋轉,並且我週期性地將我的屏幕翻轉180度(self.rotation = 180;)然後將其翻轉(self.rotation = 0)。但是,當我將其翻轉到180度時,精靈將無法正確旋轉。用觸摸旋轉雪碧 - Cocos2d
任何人有比這更好的想法?
CGFloat gRotation;
- (void)update:(ccTime)delta
{
g.rotation = gRotation;
}
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
if (CGRectContainsPoint(g.boundingBox, location))
{
CGPoint firstLocation = [touch previousLocationInView:[touch view]];
CGPoint location = [touch locationInView:[touch view]];
CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];
CGPoint firstVector = ccpSub(firstTouchingPoint, g.position);
CGFloat firstRotateAngle = -ccpToAngle(firstVector);
CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
CGPoint vector = ccpSub(touchingPoint, g.position);
CGFloat rotateAngle = -ccpToAngle(vector);
CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
gRotation += currentTouch - previousTouch;
}
}
感謝
編輯:
我進去GameConfig.h,改變#define GAME_AUTOROTATION kGameAutorotationUIViewController
到#define GAME_AUTOROTATION kGameAutorotationNone
然後進去AppDelegate.m和改變#if GAME_AUTOROTATION == kGameAutorotationUIViewController
到#if GAME_AUTOROTATION == kGameAutorotationNone
當我翻轉屏幕時,修正了精靈的旋轉,但是在兩次完整旋轉後我仍然無法停止精靈的旋轉。
是否有不同的方法來旋轉精靈?因爲grinderRotation等級取決於currentTouch和previousTouch – Jonathan 2011-06-03 18:30:50
您可以使用UIPanGestureRecognizer類來檢測只有一個手指(iOS 4或更高版本)的拖動。 – 2011-06-03 19:22:58
我在答案中加入了一個例子... – 2011-06-03 19:29:06