Hello,
I’m not sure if this is a known issue (I’ve tried searching), or event an issue at all.
Basically, I’m trying to create a cursor-like object in my game that appears when the user touches the screen, moves with the user’s finger, and disappears when the user lifts the finger up. All is well and good until I introduce buttons.
I would like to have it so the cursor behaves regardless of whether the user has rolled over/off a button or other object. Now, I have a basic understanding of event propagation, so naturally all of my button listeners return false so that the touch events bubble up to the Runtime object where my cursor object is listening. Thus, my cursor and my buttons should be able to update.
The problem occurs when I touch down on the stage, roll over a button, then release. It also occurs when I touch down on a button, roll off the button, then release. Any time such change in context occurs, it appears the events don’t propagate to the Runtime object, even though I ‘think’ it should. It is as if the event is not fired at all.
Here is the basic code…
[lua]local function onButtonEvent (event)
– Button event function.
if “release” == event.phase then
– Do stuff…
end
– Return nothing so event is propagated.
end
– Button creation.
button = widget.newButton{
left = x,
top = y,
width = w,
height = h,
onEvent = onButtonEvent
}
– Also should note the button’s are invisible but hit-testable.
button.alpha = 0
button.isHitTestable = true
group:insert(button.view)[/lua]
[lua]local function onTouch (event)
if “began” == event.phase then
– Show cursor.
elseif “moved” == event.phase then
– Move cursor.
elseif “ended” == event.phase or “cancelled” == event.phase then
– Hide cursor.
end
end
Runtime:addEventListener(“touch”, onTouch)[/lua]
I should also note that I’ve tried adding button:addEventListener(“touch”, onButtonEvent) instead of passing an event handler in the button’s constructor, but that didn’t work. I’ve also read up on the whole display.getCurrentStage:setFocus(button) deal and so I tried that as well, which also didn’t work. I’ve also tried just passing the event manually to the cursor object but that didn’t work either, it is as if the event is not firing at all.
Has anyone else been able to solve this?
Many thanks,
Varen [import]uid: 86792 topic_id: 23479 reply_id: 323479[/import]