Skip to content

Instantly share code, notes, and snippets.

@njt1982
Forked from christophercotton/OpaqueLayer.h
Last active January 4, 2016 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njt1982/8608940 to your computer and use it in GitHub Desktop.
Save njt1982/8608940 to your computer and use it in GitHub Desktop.
// Feel free to use. MIT License
#import "cocos2d.h"
// Layer that will just capture any touch events on it
@interface OpaqueLayer : CCLayerColor
@end
// OpaqueLayer.m
#import "OpaqueLayer.h"
@implementation OpaqueLayer
- (id) initWithColor:(ccColor4B)color width:(GLfloat)w height:(GLfloat) h {
if( (self=[super initWithColor:color width:w height:h]) ) {
[self setTouchPriority:kCCMenuHandlerPriority];
[self setTouchMode:kCCTouchesOneByOne];
[self setTouchEnabled:YES];
}
return self;
}
-(void) registerWithTouchDispatcher {
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self
priority:_touchPriority
swallowsTouches:_touchSwallow];
}
// just swallow any touches meant for us
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint point = [self convertTouchToNodeSpace:touch];
CGRect rect = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
return CGRectContainsPoint(rect, point);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment