Xenko基礎API筆記2-手勢

來源:互聯網
上載者:User

標籤:

互動:Drag Gesture

Type : Continuous

Configuration class: GestureConfigDrag

Event class: GestureEventDrag

Action description:The user touched the screen, performed a translation and withdraw its finger(s).

Comments: The number of finger on the screen cannot vary during the gesture. The programmer can modify the MinimumDragDistance field if he need the gesture to be triggered for smaller drags.

配置類:GestureConfigDrag
事件類別:GestureEventDrag
動作描述:使用者觸控螢幕幕時,進行了翻譯和撤回手指(s)。
評論:手指在螢幕上的數量不能改變姿態。程式員可以修改MinimumDragDistance欄位如果他需要被觸發的動作小拖。

Flick Gesture

Type : Discrete

Configuration class: GestureConfigFlick

Event class: GestureEventFlick

Action description:The user touched the screen, performed a quick straight translation and withdraw its finger(s).

Comments: The number of finger on the screen cannot vary during the gesture. The programmer can modify the MinimumFlickLength field to constrain the flick to have a minimum length.

類型:離散
配置類:GestureConfigFlick
事件類別:GestureEventFlick
動作描述:使用者觸控螢幕幕時,執行一個快速直接翻譯和撤回手指(s)。
評論:手指在螢幕上的數量不能改變姿態。程式員可以修改MinimumFlickLength欄位來限制有一個最小長度的電影。

 

Long Press Gesture

Type : Discrete

Configuration class: GestureConfigLongPress

Event class: GestureEventLongPress

Action description:The user touched the screen, and maintained the pressure without moving during a given time (default about 1 second).

Comments: The number of finger on the screen cannot vary during the gesture. The programmer can modify the RequiredPressTime field to change the press time.

長按手勢
類型:離散
配置類:GestureConfigLongPress
事件類別:GestureEventLongPress
動作描述:使用者觸控螢幕幕,保持不動的壓力在一個給定的時間(預設約1秒)。
評論:手指在螢幕上的數量不能改變姿態。程式員可以修改RequiredPressTime欄位改變新聞時間。

 

Composite Gesture

Type : Continuous

Configuration class: GestureConfigComposite

Event class: GestureEventComposite

Action description:The user touched the screen with two fingers, and moved them independently.

Comments: This gesture is a composition the 3 basic transformations translation, scale, rotation. It requires exactly 2 fingers on the screen. The gesture is triggered when the system detect a small translation, scale or rotation. To perform a translation, the user translates uniformly the two fingers together. To perform a scale, the user moves closer or further the two fingers from each other. To perform a rotation, the user turns the two fingers around there their middle.

複合動作
類型:連續
配置類:GestureConfigComposite
事件類別:GestureEventComposite
動作描述:使用者用兩個手指觸控螢幕幕,並獨立地移動。
評論:這個手勢是三個基本成分轉換翻譯,規模、旋轉。它需要2根手指在螢幕上。觸發手勢當系統檢測到一個小翻譯,規模或旋轉。進行翻譯時,使用者將統一在一起的兩根手指。執行規模、使用者移動接近或進一步的兩根手指。執行一個旋轉,使用者就那裡的兩個手指在他們的中間。

 

Tap Gesture

Type : Discrete

Configuration class: GestureConfigTap

Event class: GestureEventTap

Action description:The user touched the screen, and removed its fingers quickly without moving.

Comments: The number of finger on the screen cannot vary during the gesture.The programmer can modify the RequiredNumberOfTaps field to decide the number tap that he wants to detect. Note that to be able to distinguish single taps from multi-tap taps, the system has to wait a given time and thus introduces latency in tap events. If the programmer is interested only in single taps, he can put the MaximumTimeBetweenTaps field to 0 to avoid this latency.

點選手勢
類型:離散
配置類:GestureConfigTap
事件類別:GestureEventTap
動作描述:使用者觸控螢幕幕,並刪除其手指快速不動。
評論:手指在螢幕上的數量不能改變姿態。程式員可以修改RequiredNumberOfTaps欄位決定利用他想檢測數量。注意,能夠區分單從轉接插座水龍頭水龍頭,系統必須等待一個給定的時間,因此介紹了延時水龍頭事件。如果程式員只對單一的水龍頭感興趣,他可以把MaximumTimeBetweenTaps欄位為0來避免這種延遲。

 

Usage

By default, the input system does not recognize any Gesture. To start (resp. stop) some gesture recognition the programmer has to add (resp. remove) gesture configurations to the @‘SiliconStudio.Xenko.Input.ActivatedGestures‘ collection. Once a gesture is activated for recognition, its associated configuration is frozen and the user cannot modify it any more. If the user wants to stop all gesture recognition he can directly clear the collection.

Code: Activate/Desactivate Gestures Recognitions

var singleTapConfig = new GestureConfigTap(); // create the configuration of the gesture we want to recognizeInput.ActivatedGestures.Add(singleTapConfig); // start the tap gesture recognitionvar doubleTapConfig = new GestureConfigTap(2, 1); // create the configuration of the gesture we want to recognizeInput.ActivatedGestures.Add(doubleTapConfig ); // start the double tap gesture recognition // ...Input.ActivatedGestures.Remove(singleTapConfig); // stop the tap gesture recognition// ...Input.ActivatedGestures.Clear(); // stop all remaining gesture recognitions

Each configuration class has a parameterless constructor corresponding to the default gesture configuration. Special constructors have also been implemented for parameters that the programmer may modify frequently. Other parameters correspond to fields that are not recommended to modify to keep a good coherency of the system. Those fields can be modified by accessing the corresponding properties.

Code: Set gesture configuration

var singleTapConfig = new GestureConfigTap(); // default config for the gesture.var doubleTapConfig = new GestureConfigTap(2, 2); // personalize the gesture config by using the dedicated constructorvar noLatencyTap = new GestureConfigTap() { MaximumTimeBetweenTaps= TimeSpan.Zero }; // personalize the gesture config by directly accessing the desired property (user must be aware of was he does, this may break the input system coherency in some cases)

The programmer can access the recognized gestures via the @‘SiliconStudio.Xenko.Input.IInputManager.GestureEvents‘ collections. The collection is automatically cleared every frame.

Code: Access Gesture events

var currentFrameGestureEvents = Input.GestureEvents;

One can use the Type field to identity the gesture type and then cast it to the appropriate event type to have extra info about the event.

Code: Identifying the gesture type

foreach( var gestureEvent in Input.GestureEvents){       if (gestureEvent.Type != GestureType.Tap) // determine if the event is from a tap gesture continue; GestureEventTap tapEvent = (GestureEventTap) gestureEvent; // cast the event the specific tap event class log.Info("Tap position: {0}.", tapEvent.TapPosition); // access tap event specific field}

One can know the gesture state by analyzing the @‘ SiliconStudio.Xenko.Input.GestureEvent.State‘ field.

Code: Identifying the event state

switch(compositeGestureEvent.State){case GestureState.Began:    image.ComputePreview();    break;case GestureState.Changed:    image.TransformPreview(compositeGestureEvent.TotalScale, compositionGestureEvent.TotalRotation);    break;case GestureState.Ended: image.TransformRealImage(compositeGestureEvent.TotalScale, compositionGestureEvent.TotalRotation); break;default: break;}

Xenko基礎API筆記2-手勢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.