Forcing a touch event for a 'mouse' cursor?

I’m looking into getting our adventure engine, and thus Forever Lost and other games, working on Ouya however have a quick question first. What do you think would be the best way to essentially make a cursor from the thumbstick that just fires a touch event out when you press the A button? 

Basically all the scenes in the engine have elements in them that can receive touch events and then act accordingly to what the scripts say and it would be really nice if I could just hook up the Ouya controller to a touch event so that the underlying elements don’t even know that the touch event came from a controller rather than a real touch.

Currently they are all using object touch handlers which I’m assuming is where I am going to get stuck as I really don’t want to have fire off a runtime touch event and then manually loop through each element to see if they are in the line of fire.

Any ideas?

What I’m doing, and I don’t know if this is a best practice or not, but it seems to work…  Of course I use storyboard, so adjust accordingly.

In my scene, where I have a “touch” object, I setup a runtime listener in the enterScene function that reads:

Runtime:addEventListener(“controller_a_button”, myTouchHandler)

So you end up with an touch handler like you normally would and a runtime listener that calls the same function. Now in my main.lua where I setup the key handler for the controller, I have code like:

local function onKeyEvent( event )     local phase = event.phase     local keyName = event.keyName       if phase == "up" then         event.phase = "ended"     elseif phase == "down" then         event.phase = "began"     end       event.device = nil       if keyName == "buttonA" then         event.name = controller\_a\_button"         Runtime:dispatchEvent( event )         return true

The controller makes up and down phases, so I reprogram the event table to be ended and began.  I clear the event.device entry since it’s userdata, and it was giving me an error along the way.  You probably shouldn’t need to do this, but…  Change the name of the event and dispatch it.

Your listener in your scene will fire and pass that event structure to your touch handler.  Of course if you need more of the touch event values that the controller key doesn’t have (event.x, event.y, event.time if they are missing) you would need to provide if you’re using them.

I would then need to detect all objects at the x/y of the ‘cursor’ and then fire off their individual object handlers. Is there a way to fire a ray straight through the screen essentially along the Z and get all the objects it hits? I’m not using physics though and would rather not have to.

maybe dispatch a “touch” event instead? 

Though what I would do is use non-physics collision detection and have an array of objects I’m interested in interacting with and when I get an event, I could loop over the objects and see if my event x, y was inside the content bounds of the object then dispatch a touch event to the object (or just call the object’s touch function.)

What I’m doing, and I don’t know if this is a best practice or not, but it seems to work…  Of course I use storyboard, so adjust accordingly.

In my scene, where I have a “touch” object, I setup a runtime listener in the enterScene function that reads:

Runtime:addEventListener(“controller_a_button”, myTouchHandler)

So you end up with an touch handler like you normally would and a runtime listener that calls the same function. Now in my main.lua where I setup the key handler for the controller, I have code like:

local function onKeyEvent( event )     local phase = event.phase     local keyName = event.keyName       if phase == "up" then         event.phase = "ended"     elseif phase == "down" then         event.phase = "began"     end       event.device = nil       if keyName == "buttonA" then         event.name = controller\_a\_button"         Runtime:dispatchEvent( event )         return true

The controller makes up and down phases, so I reprogram the event table to be ended and began.  I clear the event.device entry since it’s userdata, and it was giving me an error along the way.  You probably shouldn’t need to do this, but…  Change the name of the event and dispatch it.

Your listener in your scene will fire and pass that event structure to your touch handler.  Of course if you need more of the touch event values that the controller key doesn’t have (event.x, event.y, event.time if they are missing) you would need to provide if you’re using them.

I would then need to detect all objects at the x/y of the ‘cursor’ and then fire off their individual object handlers. Is there a way to fire a ray straight through the screen essentially along the Z and get all the objects it hits? I’m not using physics though and would rather not have to.

maybe dispatch a “touch” event instead? 

Though what I would do is use non-physics collision detection and have an array of objects I’m interested in interacting with and when I get an event, I could loop over the objects and see if my event x, y was inside the content bounds of the object then dispatch a touch event to the object (or just call the object’s touch function.)

I’m in the same boat.  I make point-and-click adventure games, and my latest game I’ve been working on for over a year and it has about 200 seperate scenes (using storyboard), so I was hoping to code a pointer, that somehow duplicates a tap/touch event without having to go back through and touch all 200 scenes.  I also, really wanted to have the pointer, change when it hovers over a touchable area (like most PC based point-and-click games do).  It’s not that hard for a user to blindly and quickly tap all over the screen (using a real finger) in search for the areas that are touchable, but to do the same thing with a joystick would probably be very monotonous.  But if the pointer changed into a magnifying glass or something to indicate a touchable area when it hovers over one, it would be perfect for this style of game. 

But, again, I’m looking for a way to code the pointer without having to go back and touch all my 200+ scenes.   maybe a way to call all the display objects tied to the current scene, then loop through them, etc.  figure out their coordinates, and if they’re visible, or hitTestable, etc, then modify the pointer image, then if A_button is pressed, fire the touch or tap event on the object.  I don’t know.  I haven’t looked into it far yet, it’s just on the back of my mind for when the game is complete.

@Rob - Wow, completely forgot to reply to the thread, I thought I had but must have slipped my mind. I did try do get something working however had to put it on hold to work on other stuff. Can’t actually remember what I did now. I know it sort-of works currently for most cases, I’ll have a look in the engine when I can and see what I did.

@tielore - Not surprised really that the two of us are both making point’n’click games and are after this feature :slight_smile: As above, I’ll try to have a look into our engine when I can and see what I did and how well it worked. I’m assuming I’ve done something similar to what you described but just can’t remember. Out of curiosity, what’s the new game? Got any screenshots of it, quite interested to see anything :slight_smile:

@Glitch Games - My new game is called “Mount Olympus”.  It’ll probably be released in mid March.  My games look and feel a lot like the style Joe does with his Fire Maple Games.  The basics on this one is that you are a hero who has come to Mount Olympus to discover why the Gods have disappeared.  Here’s a youtube link for the trailer.

http://www.youtube.com/watch?v=ykKHqTbPo5c

If you’re anything like me, you watch for other Corona Users who do point-and-click, I’ve played your Forever Lost (at least the first installment). So you may have also played or at least seen my last point-and-click, Tesla’s Electric Mist.  That one did really well, and has a pretty solid fan base.  You can see images and the trailer for that on my website here: 

http://icoolgeeks.com/our-games/teslas-electric-mist/

Being that we have similar fan bases, I would be happy to discuss any synergetic marketing strategies you might be interested in.  I tried to reach out to Joe last year when I released Tesla, but I think he’s too swamped with stuff like that, to give me notice I guess.  Either that or I just looked like spam to him or something.  When fans ask me to suggest other games, I always suggest the Fire Maple games, and your Forever Lost, along with a couple more depending on my mood.  You can grab my contact email off my website link above if you want to discuss something.

Wow, mind must have gone completely blank as I had actually already seen that trailer! Silly me. We’ve played Tesla in the office ourselves and we too recommend your games and Joe’s when people ask. Small world! Would be cool to help each other out yea, we’ll have a think in the office tomorrow to see what we can do and then go from there.

I’m in the same boat.  I make point-and-click adventure games, and my latest game I’ve been working on for over a year and it has about 200 seperate scenes (using storyboard), so I was hoping to code a pointer, that somehow duplicates a tap/touch event without having to go back through and touch all 200 scenes.  I also, really wanted to have the pointer, change when it hovers over a touchable area (like most PC based point-and-click games do).  It’s not that hard for a user to blindly and quickly tap all over the screen (using a real finger) in search for the areas that are touchable, but to do the same thing with a joystick would probably be very monotonous.  But if the pointer changed into a magnifying glass or something to indicate a touchable area when it hovers over one, it would be perfect for this style of game. 

But, again, I’m looking for a way to code the pointer without having to go back and touch all my 200+ scenes.   maybe a way to call all the display objects tied to the current scene, then loop through them, etc.  figure out their coordinates, and if they’re visible, or hitTestable, etc, then modify the pointer image, then if A_button is pressed, fire the touch or tap event on the object.  I don’t know.  I haven’t looked into it far yet, it’s just on the back of my mind for when the game is complete.

@Rob - Wow, completely forgot to reply to the thread, I thought I had but must have slipped my mind. I did try do get something working however had to put it on hold to work on other stuff. Can’t actually remember what I did now. I know it sort-of works currently for most cases, I’ll have a look in the engine when I can and see what I did.

@tielore - Not surprised really that the two of us are both making point’n’click games and are after this feature :slight_smile: As above, I’ll try to have a look into our engine when I can and see what I did and how well it worked. I’m assuming I’ve done something similar to what you described but just can’t remember. Out of curiosity, what’s the new game? Got any screenshots of it, quite interested to see anything :slight_smile:

@Glitch Games - My new game is called “Mount Olympus”.  It’ll probably be released in mid March.  My games look and feel a lot like the style Joe does with his Fire Maple Games.  The basics on this one is that you are a hero who has come to Mount Olympus to discover why the Gods have disappeared.  Here’s a youtube link for the trailer.

http://www.youtube.com/watch?v=ykKHqTbPo5c

If you’re anything like me, you watch for other Corona Users who do point-and-click, I’ve played your Forever Lost (at least the first installment). So you may have also played or at least seen my last point-and-click, Tesla’s Electric Mist.  That one did really well, and has a pretty solid fan base.  You can see images and the trailer for that on my website here: 

http://icoolgeeks.com/our-games/teslas-electric-mist/

Being that we have similar fan bases, I would be happy to discuss any synergetic marketing strategies you might be interested in.  I tried to reach out to Joe last year when I released Tesla, but I think he’s too swamped with stuff like that, to give me notice I guess.  Either that or I just looked like spam to him or something.  When fans ask me to suggest other games, I always suggest the Fire Maple games, and your Forever Lost, along with a couple more depending on my mood.  You can grab my contact email off my website link above if you want to discuss something.

Wow, mind must have gone completely blank as I had actually already seen that trailer! Silly me. We’ve played Tesla in the office ourselves and we too recommend your games and Joe’s when people ask. Small world! Would be cool to help each other out yea, we’ll have a think in the office tomorrow to see what we can do and then go from there.

Hi all, I’m considering bringing Doggins to OUYA, and was wondering if you had worked out a decent solution to this problem. Like you, I made a point-and-click adventure game (LucasArts-style), and don’t want to recode all of my touch events to get this working. :slight_smile:

Thanks!

  • David

Hey David, awesome to see that you’re having a go at Ouya, we’ll be following the progress to see how well point’n’clickers can do on that and similar platforms, we’d love to bring our games over to those sorts of things.

I think the closest we got to a solution was to have a cursor moving around via the joypad and then when you pressed the “click” button our engine would work out what objects are within the same area and then fire the onPress events for those elements. Naturally this only worked with AABBs so was fairly limited. Due to the way our engine was set up this was fairly trivial.

For it to work well we’d need it to work for rotated hotspots, circles, triangles, or any other shape really. Still, it seems a fairly over the top and silly solution to just being able to fire touch events whenever we wanted.

It would be great to be able to have this ability native in Corona and I’m sure that other developers would find it useful, even if just for automated tests etc in the simulator.

I’ve just preordered an Amazon Fire TV for when it’s out in the UK ( end of october ) and I’m hoping to get back into working on that sort of device for our Serenity engine.

@Glitch Games: Thanks for the info! I’m going to have to take some time to think about this one. Ideally it would behave like the simulator: your cursor initiates touch events. Hm. Like I said, going to have to think about it for awhile. :slight_smile:

I wonder how easy it would be for CL to implement that functionality natively. Would certainly be helpful and I’m assuming that the simulator already does something very similar so can’t be too tricky.

I also remember that for Ouya, at least when we were looking into it, might have changed now, you had to make sure menus etc worked via the dpad as well as the cursor.

Hi all, I’m considering bringing Doggins to OUYA, and was wondering if you had worked out a decent solution to this problem. Like you, I made a point-and-click adventure game (LucasArts-style), and don’t want to recode all of my touch events to get this working. :slight_smile:

Thanks!

  • David