views:

356

answers:

2

In my app, I'd like a method called whenever the user taps the screen (anywhere on the screen). Normally, I'd make a transparent UIButton that covers the whole screen.

If I'm using the cocos2d framework, what's the best way to do this? Is it good practice to still use UIButtons? I've been reading about MenuItems but haven't found an easy way to make one giant fully transparent menu item?

Thanks.

A: 

try implementing touchesBegan:withEvent:. You can get the location and it supports mutltitouch (if you have enabled it on that view)

Jonathan
If you are implementing a menu with cocos2d, it's a big pain to get location and then check if the button has been clicked...
Vimard
`In my app, I'd like a method called whenever the user taps the screen (anywhere on the screen). `i'm not sure what cocos2d is but the touchesBegan is called when a user taps anywhere on the screen.
Jonathan
yeah.. but that's a poor way of implementing it... Instead of using touchesbegan to get the touches and you are deciding whether a button has been clicked or not depending on some hot spot area, it's better to use the "CCMenuItem" in cocos2d... another alternate (not that great) way is to keep different buttons in different layers.. and each layer has a different touchesbegan method...
Vimard
A: 

Try using CCMenu / CCMenuItem

check this link for more info...

http://www.cocos2d-iphone.org/api-ref/0.99.2/interface_c_c_menu_item.html

Vimard