Game Development Reference
In-Depth Information
at least one finger on the touchscreen. The more nodes there are in your scene,
the larger the performance penalty will be.
Open the HelloWorldLayer.h file and add this category interface, preferably be-
fore the HelloWorldLayer interface:
@interface CCGLView (hittest)
-(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent*)event;
Now at the beginning of the HelloWorldLayer.m file add the CCGLView hit test
category implementation shown in Listing 15-4 . The hitTest method is part of the
UIView class and gets called when the UIKit framework is trying to determine which
view wants to respond to a touch event. The method either returns a UIView instance,
which should receive the touch input, or returns nil to signal that the hit test was un-
successful, in which case the UIKit framework keeps looking for other views that
might want to process the touch event.
Listing 15-4 . Preparing to Hit Test All cocos2d Scene Children
@implementation CCGLView (hittest)
-(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent*)event
UIView* hitView = [super hitTest:point withEvent:event];
if (hitView == self)
CCScene* runningScene = [CCDirector sharedDirector].runningScene;
CCArray* sceneChildren = runningScene.children;
CGPoint glPoint = [[CCDirector sharedDirector] convertToGL:point];
BOOL hit = [self hitTestNodeChildren:sceneChildren point:glPoint];
return (hit ? self : nil);
Search Nedrilad ::

Custom Search