iphone - Detect touch *anywhere on the screen* in cocos2d? -


I'm really sorry, I know that there are many questions to ask about the Cocos 2D touch detection (Including those who answer me a bunch), but I can not get any of them to work. Instead of asking my questions, I have to comment on the answer I added, but I do not have enough representatives to leave comments.

Whatever I want to do, anywhere on the screen a user closes the animation as a tap.

This is my code so far:

  - (BOOL) touches with ccTouchesBegan: (NSSet *) event: (UIEvent *) Event {NSLog (@ " Touch started "); UIT * touch = [touches any object]; CGPoint Location = [Touch Location: [Touch View]]; Location = [[Directors Shared Directors] Convert Condanet: Location]; CGRect mySurface = (CGRectMake (100, 100, 320, 480)); If (CGRCentcentsPoint (Mersfofus, Location)) {NSLog (@ "Event Handle"); Return Kaffintheld; [[Director share director] Stop Animation]; } Return kEventIgnored; NSLog (@ "Event unrecognized"); }  

I have tried both BOOL and zero , ccTouchesBegan and In the / pre> , a layer file and a cocos node file, and many other things nothing happened. Nothing reveals in the log, and the animation continues in its delightful way. What am i doing wrong

The main problem is that you [[director shared director] stopAnimation]; after back kEventHandled; than before. As soon as the return function is called, it exits, so after this, nothing will be found.

I do not have a Mac in front of me to see the rest of my code, but it sounds fine, so I think this is the main problem. If you are not also looking at NSLog (@ "Start Touch"), then you need to make sure that you are doing this in CocosNode which is Layer .

Another useful thing (once you are viewing touches) is the NSStringFromCompossible function, which allows you to easily display and debug values ​​in CGPoint , You can do something like this:

  NSLog (@ "This layer was touched on% @", NSStringFromCompoint (location));  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -