我已經CCSprite類的子類,並添加了一個UIRotationGestureRecognizer它。所以,在我的init方法我有這個iPhone Cocos2D - 手指旋轉精靈
UIRotationGestureRecognizer *rot = [[[UIRotationGestureRecognizer alloc]
initWithTarget:self action:@selector(handleRotation:)] autorelease];
[rot setDelegate:self];
[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:rot];
,然後我有方法
- (void)handleRotation:(UIRotationGestureRecognizer *)recognizer {
float rotation = [recognizer rotation];
self.rotation += rotation;
}
它完美的作品,但它有實際的姿態和旋轉本身之間存在着巨大的滯後。我會說手勢和精靈響應之間差不多0.5秒。
我該如何解決這個問題?謝謝。
注:第一次評論後,我增加了兩個識別到的精靈:UIPinchGestureRecognizer和UIPanGestureRecognizer。我還添加了委託方法shouldRecognizeSimultaneouslyWithGestureRecognizer並將其設置爲YES。
做完這個和檢查後,捏和平移手勢就像地獄一樣快。另一方面,旋轉繼續緩慢。通過添加這兩個其他手勢識別器,沒有降低旋轉速度。另外兩個響應流體和快速,UIRotationGestureRecognizer是緩慢的。
你是否在視圖上設置了其他手勢識別器? – sergio
沒有。你認爲什麼意思?精靈?這是我的問題。當使用[[CCDirector sharedDirector] openGLView]添加gestureRecognizer時,這個openGLView聽起來像是擁有所有圖形的主openGLView。這不應該只設置爲精靈?如果是這樣,我該怎麼做? – SpaceDog
我的意思是正確的'openGLView'。將手勢識別器附加到該視圖(正如您所說的主視圖)是正確的,因爲它是您唯一的視圖。我也這樣做,並且不會有任何延遲。如果你正在使用更多的手勢。識別器,那麼可能會有一些interacion,我認爲 – sergio