Created
January 5, 2012 04:25
-
-
Save christophercotton/1563708 to your computer and use it in GitHub Desktop.
Basic Cocos2d Layer to swallow all the touch events on it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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