Hi guys,
I’m having a hard time figuring out something that perhaps is simple but I thought I could reach out to you:
Let’s say I have a screen with 2 buttons that I select by swiping the apple remote. When the scene is loaded, I would like the button on the left to be selected, and then when the user swipes right, I’d like to select the button on the right. I get this working, but the thing is that before I can select the button on the right, when running the app for the first time I have to swipe twice. It seems like the app can’t detect the first swipe… I’m attaching the code below and if you could try it out just install the app on the apple tv and try swiping right… you will notice that it doesn;t work, unless you swipe again. Is that something I’m missing?
Cheers,
Marcos
local buttons = {} local selectedButton local button1 = display.newRect( 0, 0, 100, 100 ) button1.x =100 button1.y = 100 local button2 = display.newRect( 0, 0, 100, 100 ) button2.x =300 button2.y = 100 buttons[1] = button1 buttons[2] = button2 selectedButton = 1 buttons[selectedButton]:setFillColor( 0,1,1 ) local resetAt0 = true local function onAxisEvent( event ) local previousButton = selectedButton local mappedEvent = { name = "key", phase = "up", keyName = "" } local delta = event.normalizedValue if not event.axis or (event.axis.type ~= 'y' and event.axis.type ~= 'x') then return end if resetAt0 and delta ~= 0 then return end resetAt0 = false if math.abs(delta) \> 0.5 then if event.axis.type == "x" then if delta \< 0 then mappedEvent.keyName = "left" selectedButton = 1 elseif delta \> 0 then selectedButton = 2 mappedEvent.keyName = "right" end end buttons[previousButton]:setFillColor( 1 ) buttons[selectedButton]:setFillColor( 0,1,1 ) resetAt0 = true end if mappedEvent.keyName ~= "" then Runtime:dispatchEvent( mappedEvent ) print( "DISPATCHED: " .. mappedEvent.keyName ) end end Runtime:addEventListener( "axis", onAxisEvent )