[Resolved] track how long user touches screen not working with ipad

I have some simple code that measures how long the user touches the screen… It works fine on my android phone, but not with the ipad.

Here is sample code.
initial_time set in the 'began" phase

At the end phase,
if (e.time - initial_time) > 1000 then

do something

end [import]uid: 31039 topic_id: 24832 reply_id: 324832[/import]

Can you post a code snippet that we can actually run? (Plug and Play?)

If you can do that I’ll try to test it :slight_smile: [import]uid: 52491 topic_id: 24832 reply_id: 100763[/import]

Seems to work occasionally. I’m opened to other ways of doing this.


local _W = display.contentWidth;
local _H = display.contentHeight;
local elapsedT = 0;

– A text object is created and is aligned left at point x=20
local textObj = display.newText(“A short string”, 0,30, nil, 14);
textObj:setReferencePoint(display.CenterLeftReferencePoint);
textObj.x = 20;

local function tchScreen(e)

textObj.isVisible = false
t = e.target
display.getCurrentStage():setFocus(t)

local phase = e.phase

if(e.phase == “began”) then
– Access the seconds that have elapsed
elapsedT = system.getTimer()

elseif (e.phase == “ended”) or phase == “cancelled” then
print ("time “…(system.getTimer() - elapsedT)…” elapsed time "…elapsedT)
if(system.getTimer() - elapsedT) > 1000 then
textObj.isVisible = true
return true
end
end
end

Runtime:addEventListener(“touch”,tchScreen)
[import]uid: 31039 topic_id: 24832 reply_id: 101017[/import]

Try this and let me know if you get the result you want

[code]
local timer = display.newText( “”, 150, 150, native.systemFont, 16 )

local function touchScreen( event )

if event.phase == “began” then
text1 = system.getTimer()
end
if event.phase ==“ended” or “cancelled” then
text3 = system.getTimer()
timer.text = text3 - text1
end
end
Runtime:addEventListener( “touch”, touchScreen )
[/code] [import]uid: 77199 topic_id: 24832 reply_id: 101032[/import]

Thanks. Its seems to have resolved the problem, but I’m unsure why. [import]uid: 31039 topic_id: 24832 reply_id: 101694[/import]