Proper button respond

Hello,

i have two joystick buttons to move object on screen, it works like that
[lua]local function go_left(event)
if event.phase == “began” then
left = 1
else left = 0
end
return true
end

local function go_right(event)
if event.phase == “began” then
right = 1
else right = 0
end
return true
end

joystickLeft:addEventListener(“touch”, go_left)
joystickRight:addEventListener(“touch”, go_right)
local function going()
if left == 1 then
player.x = player.x - 3
end
if right == 1 then
player.x = player.x + 3
end
end
Runtime:addEventListener(“enterFrame”, going)[/lua]

and on first glance its ok, but it bugs sometime when i clicked joystick and then moved cursor(finger) away

how can i make button respond only on continuous touch? [import]uid: 16142 topic_id: 16869 reply_id: 316869[/import]

I think you need to check on the “moved” phase:

[lua]if event.phase == “moved” then[/lua]

Raúl Beltrán
MIU Games
[import]uid: 44101 topic_id: 16869 reply_id: 63215[/import]

“else” is already checking all phases… [import]uid: 16142 topic_id: 16869 reply_id: 63218[/import]

Ok… if I am understanding this correctly I think you need to play with the focus of the butons as in

http://developer.anscamobile.com/reference/index/stagesetfocus

and

http://developer.anscamobile.com/code/joystick

[lua] local this = event.target
local phase = event.phase

if phase == “began” then
– Start Focus
display.getCurrentStage():setFocus( this, event.id )
this.isFocus = true
elseif this.isFocus then
if phase == “moved” then
– do joystick stuff
elseif phase == “ended” or phase == “cancelled” then
– End Focus
display.getCurrentStage():setFocus( this , nil )
this.isFocus = false
end
end[/lua]
Hope this helps
Raúl Beltrán
MIU Games [import]uid: 44101 topic_id: 16869 reply_id: 63229[/import]