我知道這個問題已經被問了好幾次了,相信我我已經搜索過了。我發現了一個用觸摸旋轉精靈的答案,但必須有一個更簡單的方法。用觸摸旋轉一個精靈 - Cocos2d
我需要的是讓我的精靈隨着我的觸摸旋轉。最大旋轉0最小旋轉0.
我知道我需要一些檢查。
int maxRot = 0;
int minRot = 0;
if (arrowRotation > maxRot)
{
//do or don't do something
} else if (arrowRotation < minRot)
{
//do or don't do something
}
有人能帶我以正確的方向旋轉一個精靈,觸摸,最小和最大旋轉?
這裏是我認爲是複雜或可以用更簡單的方式完成的代碼。
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
//acquire the previous touch location
CGPoint firstLocation = [touch previousLocationInView:[touch view]];
CGPoint location = [touch locationInView:[touch view]];
//preform all the same basic rig on both the current touch and previous touch
CGPoint touchingPoint = [[CCDirector sharedDirector] convertToGL:location];
CGPoint firstTouchingPoint = [[CCDirector sharedDirector] convertToGL:firstLocation];
CGPoint firstVector = ccpSub(firstTouchingPoint, _arrow.position);
CGFloat firstRotateAngle = -ccpToAngle(firstVector);
CGFloat previousTouch = CC_RADIANS_TO_DEGREES(firstRotateAngle);
CGPoint vector = ccpSub(touchingPoint, _arrow.position);
CGFloat rotateAngle = -ccpToAngle(vector);
CGFloat currentTouch = CC_RADIANS_TO_DEGREES(rotateAngle);
//keep adding the difference of the two angles to the dial rotation
arrowRotation += currentTouch - previousTouch;
}
在此先感謝!
添加鏈接到你認爲太複雜的解決方案 - 這可能是唯一的方法;) – deanWombourne
我用代碼更新了我的問題! – Jonathan
你的意思是maxRot和minRot都是= 0。 – KDaker