looping through display objects in storyboard

So, I build point-and-click adventure games.  I want to try to add ouya support.  But to do this, I need to be able to find and loop through all the display objects.  So, I can have a floating pointer on the screen, that changes to a finger or magnifying glass when it hovers over a clickable display object.  Plus the ability to call the tap or touch event on any functions on those display objects. 

I’m having a hard time figuring out how to even find the display objects.

I’m using storyboard.  And upon scene creation it sets up the group object as follows:

local group = self.view  

Every display object gets added to group

group:insert( room );  

But when I try to loop through group to find these display objects, I find two variables with type = “userdata” and “table”. 

When I then loop through the table variable, I get more tables, and functions.

So I built some code that keeps looping through all the nested tables looking for anything familiar, and it appears there are literally over 13,000 nested tables in the group object.  Eventually I get a stack overflow error. And I’m not finding anything familiar.

Help me figure out how to find the display objects I’ve added to the group.

Thanks

local stage = display.getCurrentStage() for a = 1, stage.numChildren,1 do stage[a]........... end

@jstrahan - thanks… that seems to be working.  I can loop through and check they all have x,y, width, height.  I still don’t know how to see the name of the object, but not sure if I need that. 

Now, the next question would be around how to get a click from the ouya pointer, to the object.  Can I just create a touch or tap at the x,y coords, or do I need to actually send a touch/tap event directly to the object?  If I have to send it directly to the object, how do I know which objects are on top?  Which would intercept the touch/tap first, etc.

Hopefully we can just imitate a touch/tap event on the screen and let corona figure out which object gets it first.

if you need to get the name when you create an object you could do

cir = display.newCircle(............ cir.objectName="cir"

then when you cycle thru objects you can read the objectName variables

haven’t used ouya

as far as which is on top the last stage[a] object should be on top

is there a way to spoof a touch or tap event at a specific coordinates?  I really thin I need to be able to do this, because calling the tap/touch listeners on the individual objects will be crazy hard, since some use touch, and some use tap, and some are hidden, some with hitTestable turned on, some that use variables to determine if they intercept the touch or not, etc.  So basically it will be a nightmare to manually determine which object should get the call, where if we can simply spoof a real touch event, it will do all that for me.

I don’t think I actually need to know the object names, it would just be nice to be able to access during testing this code.  But adding an extra variable to each object for this purpose isn’t doable since I have over 150 scenes in this game so far.

The way I was doing this I was making use of my touch functions by creating my own event table that set the event phase to began or ended based on the key’s up or down phase and setting the rest of the variables in the event table. See:  http://docs.coronalabs.com/api/event/touch/index.html

Then just call your touch handler passing in the event table as a parameter.

Rob

how can i tell if a display object has a listener on it?  and if so, if it’s a “tap” or a “touch” listener?

if object,_functionListener, touch or object._functionListeren.tap or object._tableListener.touch or object._tableListener.tap then

Tried that, but getting error that the _functionListener is nil… or any of the above variations.  Here is my code:

local stage = display.getCurrentStage()   for a = 1, stage.numChildren,1 do       if stage[a].x then      print ("stage Object type = " .. type(stage[a]) .. "  object = " .. tostring(stage[a])          .. " x=".. stage[a].x .. ", y=".. stage[a].y .. ", w=".. stage[a].width .. ", h=".. stage[a].height);         if stage[a].\_functionListener.touch or stage[a].\_functionListener.tap or stage[a].\_tableListener.touch or stage[a].\_tableListener.tap then             print("has a listener")         end     end   end  

Here’s the error:

attempt to index field ‘_functionListener’ (a nil value)

All of these objects on this particular scene have either a tap or touch listener and function.
 

try adding ~= nil to each condition check

already tried that, no matter what, all those are always nil.  But on this scene, all the display objects have either a tap or touch listener. 

need to check for _functionListener then for _functionListen.touch and tap. then same for _tableListener

Please keep in mind that our standard is to prefix **private** variables and methods with an underscore.  We are subject to change these attribute and method names at any time and without warning.  Use this technique at your own risk.

Rob

both stage[a]._functionListener and stage[a]._tableListener are nil on all of the objects.

local stage = display.getCurrentStage() for a = 1, stage.numChildren,1 do stage[a]........... end

@jstrahan - thanks… that seems to be working.  I can loop through and check they all have x,y, width, height.  I still don’t know how to see the name of the object, but not sure if I need that. 

Now, the next question would be around how to get a click from the ouya pointer, to the object.  Can I just create a touch or tap at the x,y coords, or do I need to actually send a touch/tap event directly to the object?  If I have to send it directly to the object, how do I know which objects are on top?  Which would intercept the touch/tap first, etc.

Hopefully we can just imitate a touch/tap event on the screen and let corona figure out which object gets it first.

if you need to get the name when you create an object you could do

cir = display.newCircle(............ cir.objectName="cir"

then when you cycle thru objects you can read the objectName variables

haven’t used ouya

as far as which is on top the last stage[a] object should be on top

is there a way to spoof a touch or tap event at a specific coordinates?  I really thin I need to be able to do this, because calling the tap/touch listeners on the individual objects will be crazy hard, since some use touch, and some use tap, and some are hidden, some with hitTestable turned on, some that use variables to determine if they intercept the touch or not, etc.  So basically it will be a nightmare to manually determine which object should get the call, where if we can simply spoof a real touch event, it will do all that for me.

I don’t think I actually need to know the object names, it would just be nice to be able to access during testing this code.  But adding an extra variable to each object for this purpose isn’t doable since I have over 150 scenes in this game so far.

The way I was doing this I was making use of my touch functions by creating my own event table that set the event phase to began or ended based on the key’s up or down phase and setting the rest of the variables in the event table. See:  http://docs.coronalabs.com/api/event/touch/index.html

Then just call your touch handler passing in the event table as a parameter.

Rob

how can i tell if a display object has a listener on it?  and if so, if it’s a “tap” or a “touch” listener?