-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameInput.cs
101 lines (44 loc) · 1.77 KB
/
GameInput.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Sensors;
using Windows.UI.Xaml;
using Windows.UI.Input;
using Windows.UI.Core;
namespace Project1
{
public class GameInput
{
public Accelerometer accelerometer;
public CoreWindow window;
public GestureRecognizer gestureRecognizer;
public GameInput()
{
// Get the accelerometer object
accelerometer = Accelerometer.GetDefault();
window = Window.Current.CoreWindow;
// Set up the gesture recognizer. In this example, it only responds to TranslateX and Tap events
gestureRecognizer = new Windows.UI.Input.GestureRecognizer();
gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateX | GestureSettings.ManipulationScale | GestureSettings.Tap;
// Register event handlers for pointer events
window.PointerPressed += OnPointerPressed;
window.PointerMoved += OnPointerMoved;
window.PointerReleased += OnPointerReleased;
}
// Call the gesture recognizer when a pointer event occurs
void OnPointerPressed(CoreWindow sender, PointerEventArgs args)
{
gestureRecognizer.ProcessDownEvent(args.CurrentPoint);
}
void OnPointerMoved(CoreWindow sender, PointerEventArgs args)
{
gestureRecognizer.ProcessMoveEvents(args.GetIntermediatePoints());
}
void OnPointerReleased(CoreWindow sender, PointerEventArgs args)
{
gestureRecognizer.ProcessUpEvent(args.CurrentPoint);
}
}
}