Creating an invisible button

New to programming Corona so apologies for the basic questions.

I want to create an invisible button that occupies the top third of the screen and therefore created a png file that is 320 x 160 and displayed it and set its alpha to 0. What I want to do is when this button is clicked to slide an image into this area. Clicking again will slide this image off screen and another will slide in to replace it. Hence the need for an invisible button and not manually having to add a listener to each image when it has been slid onto screen.

Unfortunately when the alpha is set to zero, it doesn’t appear to recognise tap events.

I am sure there is a better way to make an invisible button and therefore seek the advice of those with more experience.

Thanks

Paul [import]uid: 7863 topic_id: 1566 reply_id: 301566[/import]

Just add an “touch” event handler and check for touches in that location “manually”.

It may also help to use an rectangle (no need for an image at all) and set the alpha to near fully transparent. I did not check that though. [import]uid: 6928 topic_id: 1566 reply_id: 4462[/import]

Thanks for the reply OderWat

I did manage to find some code that worked as follows. Is this the same as a “touch” event handler or is a “tap” different from a “touch”? And also is what I have done the equivalent of checking for touches manually?

  
local topSlotButton = display.newRect(0,0,320,160)  
topSlotButton:setFillColor(0,0,0,0)  
  
function topSlotButton:tap (event)  
  
 -- Code here  
  
end  
  
topSlotButton:addEventListener("tap",topSlotButton)  
  

Many thanks

Paul [import]uid: 7863 topic_id: 1566 reply_id: 4463[/import]

“Tap” is different than “Touch”… but may do.

I am not sure about the status of the “Tap” event. It is currently not documented in the event handler section.

I have some sample code for my buttons here http://developer.anscamobile.com/forum/2010/07/13/button-onhold#comment-3916

But that may be to complicated for this “simple” case. [import]uid: 6928 topic_id: 1566 reply_id: 4464[/import]

Thanks for the swift reply OderWat.

I came across the tap event in some sample tutorials. I hadn’t seen the “Touch” one yet. I am going to sit down and go through the API as it seems like the sensible way to start. I am from a Flash Actionscript background so hopefully won’t be too painful getting up to speed.

Thanks for the link to your button code - I think I will look at it properly after I have studied the API as it looks a bit daunting at present.

Many thanks

Paul [import]uid: 7863 topic_id: 1566 reply_id: 4465[/import]