Skip to content

Instantly share code, notes, and snippets.

@dabing1022
Forked from christophercotton/OpaqueLayer.h
Created May 12, 2013 02:46
Show Gist options
  • Save dabing1022/5562222 to your computer and use it in GitHub Desktop.
Save dabing1022/5562222 to your computer and use it in GitHub Desktop.
// Feel free to use. MIT License
#import <Foundation/Foundation.h>
#import "cocos2d.h"
// Layer that will just capture any touch events on it
@interface OpaqueLayer : CCLayerColor {
}
@end
#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.isTouchEnabled = YES;
}
return self;
}
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
// 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