2013年1月15日火曜日

KKInputの設定メモ。適当訳つきだったり。

さて。Kobold2dのKKInputについて学習を開始。
タップやダブルタップなどのgestureに関する実装と設定。
メモとして、APIリファレンスから、そのまま引用。
http://www.kobold2d.com/display/KKDOC/KKInput+Gestures#KKInputGestures-KKInputGestureRecognizerSupport

見直しながら、使えるようになりましょう、自分。
適当な訳をメモをかねて勉強のために書きましたが、あくまで適当です。間違えていたら、ご愛敬。よかったら教えて下さい。
KKInput Gesture Recognizer Support
KKInput supports all built-in UIGestureRecognizer gestures:
GestureTapDouble-
Tap
Long-
Press
SwipePanRotationPinch
Discrete
Fingers1111122
The Tap, Double-Tap and Swipe gestures are discrete events that are true only during the frame the gesture was recognized. All other gestures are continuous, meaning they continue to update their state until the gesture ends.タップとダブルタップとスワイプは、gestureが認識されたフレーム内でのみtrueで独立したイベントだと。
KKInput only supports single-finger gestures, with the exception of Rotation and Pinch which require two fingers by definition.
ローテーションとピンチ以外は、一本指でのgestureのみサポートする、と。
While you can create recognizers for two, three or more finger taps, long-presses, swipes and so on, using such gestures in games has very limited application. If you have a good use case for such gestures, feel free to make a request in the Kobold2D Feedback section.
3,4本などの指での長押しなどは、普通のゲームではあまり使われないから、もし必要ならリクエストしてね、と。 
Gestures can influence each other
Not all gestures can be enabled at the same time without influencing each other.互いに影響し合わないのでなければ、同時に複数のgestureはenableにできない、と。
  • Tap and Double-Tap
    • If both are enabled, the Double-Tap gesture must fail before the Tap gesture is recognized. This introduces an unavoidable delay before the Tap gesture is recognized.
  • Pan and Swipe
    • If both are enabled, they will be recognized simultaneously. パンとスワイプを両方設定したら、同時に認識されると。
  • Rotation and Pinch
    • If both are enabled, they will be recognized simultaneously. This means that you can implement a rotate & zoom action by enabling both gestures at the same time.回転とピンチの設定は、両方同時にしてもOK,と。
    •  You should not use Pan or Long-Press simultaneously with Rotation and Pinch, because doing so will make it difficult for the user to correctly initiate the rotation or pinch gesture.回転とピンチと同時に、パンか長押しを使ったらダメよ、と。
Testing if Gesture Recognizers are Available
Gesture Recognizers and thus KKInput gestures are available on iOS 3.2 and newer. To test if the current device supports gestures check the gesturesAvailable property: iOS3.2以降でないと、KKInputは使えない、と。チェックのやり方は、以下。
if ([KKInput sharedInput].gesturesAvailable) {...}
Enabling Gestures
Each gesture can be enabled/disabled separately. You will have to set the appropriate "Enabled" properties. If gestures are not supported on the current device (pre iOS 3.2), gestures will not be enabled. 以下のような設定で、適切に一個一個のgestureを設定すべし、と。
KKInput* input = [KKInput sharedInput];
input.gestureTapEnabled = YES;
input.gestureDoubleTapEnabled = YES;
input.gestureLongPressEnabled = YES;
input.gestureSwipeEnabled = YES;
input.gesturePanEnabled = YES;
input.gestureRotationEnabled = YES;
input.gesturePinchEnabled = YES;
Gesture Location
All gestures have their own gestureXXXLocation property which returns the location of the gesture in Cocos2D OpenGL view coordinates. cocos2dのOpenGL view coordinates内の、gesture位置を取得できる、と。
For Tap and Double-Tap it is the location where the finger touched the screen. For Swipe it is the location where the Swipe gesture started. タップとダブルタップは、スクリーンにタッチした場所。スワイプは、スワイプgestureを始めた場所。
For LongPress and Pan gestures it is the current location of the finger. For Rotation and Pinch the location is the middle point between the two fingers. 長押しと、パンは、今指がある場所。回転とピンチは、二本の指の真ん中の場所。 
CGPoint pos;
KKInput* input = [KKInput sharedInput];
pos = input.gestureTapLocation;
pos = input.gestureDoubleTapLocation;
pos = input.gestureLongPressLocation;
pos = input.gestureSwipeLocation;
pos = input.gesturePanLocation;
pos = input.gestureRotationLocation;
pos = input.gesturePinchLocation;
CGPointの変数に、KKInput型の変数で、input.gestureTapLocationなどで位置を取得格納できる、と。
   CGPoint pos;KKInput* input =[KKInput sharedInput];
          pos=input.gestureTapLocation;
          pos=input.gestureDoubleTapLocation;
      など、と。
Discrete Gestures: Tap, Double-Tap and Swipe
The Tap, Double-Tap and Swipe gestures are discrete, ie they're only true in the frame they happened. Therefore they can only be checked with "ThisFrame" properties: タップとダブルタップとスワイプは、独立したgestureであるから、"ThisFrame"プロパティでのみチェック可能、と。
KKInput* input = [KKInput sharedInput];
if (input.gestureTapRecognizedThisFrame) {...}
if (input.gestureDoubleTapRecognizedThisFrame) {...}
if (input.gestureSwipeTapRecognizedThisFrame) {...}
Only when a "ThisFrame" property is true will the corresponding gestureXXXLocation property contain a meaningful location. "ThisFrame"プロパティがtrueになったときのみ、関連のgestureXXXLocationプロパティが、意味のある位置を格納する、と。
Continuous Gestures: LongPress, Pan, Rotation and Pinch
All continuous gestures have a gestureXXXBegan property which is true the moment the gesture was first recognized, and stays true until the gesture ends or is cancelled. 全ての継続的gestureがgestureXXXBeganプロパティでtrueになるのは、gestureが最初に認識され、gestureが終わるまでtrueでいるか、もしくはcancelledになるまでtrueでいる場合である、と。(XXXって何かと思ったら、Pan,とかLongPressのことね。)(ま、長押しとかパンとかが、押しっぱなしであればtrueだよ、ということか。) 
KKInput* input = [KKInput sharedInput];
if (input.gestureLongPressBegan) {...}
if (input.gesturePanBegan) {...}
if (input.gestureRotationBegan) {...}
if (input.gesturePinchBegan) {...}
Only while the "Began" property is true will the corresponding gestureXXXLocation property contain a meaningful location.(Beganプロパティがtrueの場合だけ、、関連のgestureXXXLocationプロパティが意味のある位置を格納する、と。)
Swipe Gesture Properties
The swipe gesture has an additional property gestureSwipeDirection of type KKSwipeGestureDirectionwith which you can determine the direction of the swipe: right, left, up or down.(KKSwipeGestureDirectionで、スワイプ方向についての処理を設定しておける、と。)
KKInput* input = [KKInput sharedInput];
KKSwipeGestureDirection dir = input.gestureSwipeDirection;
switch (dir)
{
    case KKSwipeGestureDirectionRight:
        // direction-specific code here
        break;
    case KKSwipeGestureDirectionLeft:
        // direction-specific code here
        break;
    case KKSwipeGestureDirectionUp:
        // direction-specific code here
        break;
    case KKSwipeGestureDirectionDown:
        // direction-specific code here
        break;
}
Pan Gesture Properties
The Pan gesture has two extra properties gesturePanTranslation and gesturePanVelocity.The translation is a CGPoint that contains how far, in points, the finger has moved relative to the point where the Pan gesture began  (gesturePanVelocityは、パンのgestureが始まった位置からどのぐらい離れたかのプロパティを持つ、と。).The velocity is a CGPoint that tells you how fast the finger is currently moving across the screen, in points per frame.(gesturePanVelocityでは、どのぐらい指がスクリーン上を早く動いているかを、フレームごとにCGPointとして取得、と。)
KKInput* input = [KKInput sharedInput];
CGPoint translation = input.gesturePanTranslation;
CGPoint velocity = input.gesturePanVelocity;
input.gesturePanTranslation = newTranslation;
You can also modify the gesturePanTranslation property. If you do so, the gesturePanVelocity property is reset.
Rotation Gesture Properties
The Rotation gesture knows two exclusive properties gestureRotationAngle andgestureRotationVelocity.(AngleとVelocity、角度と速度のプロパティを持つ、と。) The angle is is the current rotation angle, in degrees (0-360). You can directly assign the angle to a node's direction property. The velocity tells you how fast the user is performing the rotation gesture, in degrees per frame.
KKInput* input = [KKInput sharedInput];
aSprite.direction = input.gestureRotationAngle;
float velocity = input.gestureRotationVelocity;
input.gestureRotationAngle = 180.0f;
You can also modify the gestureRotationAngle property. If you do so, the gestureRotationVelocityproperty is reset.
Pinch Gesture Properties
The Pinch gesture has two properties gesturePinchScale and gesturePinchVelocity(PinchScaleとPinchVelocityの二つのプロパティ。). Scale is the relative scale factor of the two fingers(二本指が離れるか、近寄るか), it increases the further the two fingers move apart, it decreases the closer they move towards each other. The scale property can be directly assigned to a node's scaleproperty. The velocity is how fast the fingers are moving towards or away from each other, in scale factor per frame.
KKInput* input = [KKInput sharedInput];
aSprite.scale = input.gesturePinchScale;
float velocity = input.gesturePinchVelocity;
input.gesturePinchScale = 2.0f;
You can also modify the input.gesturePinchScale property. If you do so, the input.gesturePinchVelocityproperty is reset.
Cancelling a Continuous Gesture Recognizer
If you want to ignore a continuous gesture after it began, you can cancel it simply by disabling and re-enabling the gesture like this: (継続的なgestureを無視させたい場合、ね。)
if (input.gesturePanBegan)
{
   // don't like continuing with the gesture? Reset it:
   input.gesturePanEnabled = NO;
   input.gesturePanEnabled = YES;
}
Note that this will release the previous gesture recognizer and allocate a new one, so you should avoid doing that every frame.
Accessing the underlying UIGestureRecognizer objects
As of Kobold2D v1.0.2 KKInput has the following properties with which you can gain access to the UIGestureRecognizer instances used by KKInput. This allows you to use all of the gesture recognizer features supported by UIGestureRecognizer and concrete subclasses, since KKInput only exposes the most frequently needed features.
UITapGestureRecognizer *    tapGestureRecognizer;
UITapGestureRecognizer *    doubleTapGestureRecognizer;
UILongPressGestureRecognizer *  longPressGestureRecognizer;
UIPanGestureRecognizer *    panGestureRecognizer;
UIRotationGestureRecognizer *   rotationGestureRecognizer;
UIPinchGestureRecognizer *  pinchGestureRecognizer;
Note that these properties may return nil if the gesture recognizer is not enabled.
You should not retain these properties! The gesture recognizers are retained by KKInput until you disable the gesture. Once you re-enable the gesture, a new gesture recognizer is allocated which would then be used rather than your retained instance.
In Mac OS X builds these properties are declared to be of type id and will always return nil.
By default the delegate property of the gesture recognizers is the KKInputGesture class. Therefore you should not modify the delegate or KKInput would stop processing that gesture. If you need to use your own delegate you'll be better off to just create the instance of UIGestureRecognizer yourself and not use KKInput's gestures. You may want to use some of the code in the handleXXXGesture methods in the KKInputGesture class though.
Labels:

0 件のコメント:

コメントを投稿