More memory efficient? An invisible image, or runtime listener for touches?

Ahoy!

I'm currently building an application that utilizes a faux "drop-down" menu for iPad. I've written a method that listens for the user's touch, and if it's outside a certain coordinate range, dismisses the menu.

I also have a scrollView underneath, which seems to be intercepting the touches, and not allowing the menu to dismiss.

A co-worker recommended just creating a screen-wide, invisible button in-between the scrollView and menu that will intercept the touch and enable the menu to dismiss itself.

Given those two options: calculating the touch coordinates (and adding a Runtime listener), or creating the invisible button, which one is more memory efficient? Or, the better option, in general?

Thank you very much!

I went with the invisible option. I didn't use an image, but a

1
2
3
local bgButton = display.newRect(0,0,display.contentWidth, display.contentHeight)
foregroundGroup:insert(bgButton)
bgButton:addEventListener("touch", doStuff)

Hmm...

I'm trying that, but the console is telling me that it is having troubling indexing "bgButton" (a nil value).

What does that error mean?

That means it can't find it...make sure that you define bgButton before you try to do anything with it.

I'm still having an issue with the background "stealing" the touches of the buttons I have displayed on top of it.

Any suggestions?

Post some code, I have no idea what you are talking about!!

It's okay. I've solved/compensated for the problem by calculating the coordinates of the touches, and only allowing the background to dismiss if the touch exists within a certain set of coordinates (plotted around the space occupied by the buttons on-screen).

I suspect you have a simple ordering problem. Events propogate from one object to another based on their order on the screen.

Normally you load a background image, then you load some scenery/enemies then you load your actor and you might even have more elements in front of them. Think of your scene as a series of layers.

The order is controlled by the order you create the objects and insert them into a display group.

So if your creating your objects like this:

full screen background
small object to be touched
full screen invisible button

The full screen invisible button is going to capture ALL touches and your object will never see them. But if you order them like this:

full screen background
full screen invisible button
small object to be touched

Then when you touch the object it will get the touch event and not the invisible button. You **MUST** "return true" from the event handler or the invisible button will also get the touch event.

The best way to control the order is to insert the objects into your display group in the order you want them. Corona SDK does support two API Calls that will send an object to the back or bring it to the front which is useful when you're spawning enemies and they become the top objects and you need to move things like controls above the enemies. It's someting like:

smallobject:toFront()

I wish Corona SDK offered more layering controls like moveBack and moveForward to give us even more controls over our layering.

Hey Rob,

I've tried that, and still, the background was receiving touches.

So, I've managed to tackle the problem for the time being, but I appreciate your help nonetheless.

Thanks again!

views:1600 update:2011/11/14 9:16:56
corona forums © 2003-2011