Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Is there a better implementation to record gesture? — Gideros Forum

Is there a better implementation to record gesture?

koeosstudiokoeosstudio Member
edited July 6 in Code snippets
I have a function that records gesture/or doodle for my game.
When the user start touching the screen, the function will start recording the movement of the finger in the screen.
Then when the user release his finger from the screen, the function will replay the movement of the users finger.
I have a working code below, but I have a doubt on it's efficiency. I tried running it on a mid range device, it was smooth but I don't know if lower end device can handle it. Please review my code below. A better and more efficient implementation will be greatly appreciated. Thanks :)
application:	setLogicalDimensions	(720, 1440)
application:	setScaleMode			('letterbox')
application:	setOrientation			('portrait')
application:	setKeyboardVisibility	(false)
application:	setKeepAwake			(true)
application:	setFps					(60)
application:	setBackgroundColor		(0x11272c) 
w, h = application:getLogicalWidth(), application:getLogicalHeight()
-- Function that record a gesture and replays it
--Create box
local img = Pixel.new(0xffffff,1,50,50)
img:setAnchorPoint(0.5, 0.5)
--Table and array for saving coordinate
local g = {}
local i = 1
local function d(event) --Gets the starting point
	g = nil
	g = {}
	i = 1
	g[i] = {event.touch.x, event.touch.y}
stage:addEventListener(Event.TOUCHES_BEGIN, d)
local function m(event) --saves coordinate inside the table
	i = i + 1
	g[i] = {event.touch.x, event.touch.y}
stage:addEventListener(Event.TOUCHES_MOVE, m)
local function u(event) --replay the coordinates from table using gtween
	i = 1
	img:setPosition(g[i][1], g[i][2])
	local function run()
		local t = GTween.new(img, 0.01, {x = g[i][1], y= g[i][2]}, {delay = 0, ease = easing.linear, dispatchEvents = true})
		t:addEventListener('complete', function()
			if i < #g then
				i = i + 1
stage:addEventListener(Event.TOUCHES_END, u)
--I would also like to put trail on the gesture, like a doodling effect but I don't know how
+1 -1 (+2 / -0 )Share on Facebook


Sign In or Register to comment.