-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.lua
57 lines (46 loc) · 2.17 KB
/
sample.lua
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
52
53
54
55
56
57
--
-- Abstract: simple_gesture Library Plugin Test Project
--
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
-- Copyright (C) 2015 Corona Labs Inc. All Rights Reserved.
--
------------------------------------------------------------
-- Load plugin library
local simple_gesture = require "plugin.simple_gesture"
-------------------------------------------------------------------------------
-- BEGIN (Insert your sample test starting here)
-------------------------------------------------------------------------------
local screenW, screenH = display.contentWidth, display.contentHeight
-- Create a background to pick up gestures
local background = display.newRect(0.5 * screenW, 0.5 * screenH, screenW, 2 * screenH)
background:setFillColor(0)
-- Create a label to show the current gesture
local gestureLabel = display.newText("No gesture", 0.5 * screenW, 0.1 * screenH, 200, 50, native.systemFontBold, 18)
-- Print the supported gestures
print("Supported gestures: ")
local supportedGestures = simple_gesture.getSupportedGestures()
for index=1,#supportedGestures do
print(" " .. supportedGestures[index])
end
-- Set the valid gestures to just up, down, left and right
simple_gesture.setValidGestures({"up", "down", "left", "right", "poo"})
print("Valid gestures: ")
local validGestures = simple_gesture.getValidGestures()
for index=1,#validGestures do
print(" " .. validGestures[index])
end
-- Add a touch listener that calls into the gesture library
function background:touch(event)
-- Pass the event directly to the gestureListener function before doing anything else or applying any logic
local gestureResult = simple_gesture.gestureListener(event)
-- gestureResult will be nil during a gesture, false if the gesture has ended and not been recognised, and a string value if a valid gesture was recorded
if (gestureResult) then
gestureLabel.text = gestureResult
elseif (gestureResult ~= nil) then
gestureLabel.text = "No gesture"
end
end
background:addEventListener("touch", background)
-------------------------------------------------------------------------------
-- END
-------------------------------------------------------------------------------