Skip to content

Commit

Permalink
Updated code for cocos2d v. 0.99.4. Also added auto-registering/unreg…
Browse files Browse the repository at this point in the history
…istering for touch events when a Node is entered/exited
  • Loading branch information
Jeremy Flores committed Jul 22, 2010
1 parent e18f52c commit 6e5e8ae
Show file tree
Hide file tree
Showing 341 changed files with 52,585 additions and 2,500 deletions.
Binary file added Shared/.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions Shared/CCNode+Additions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CocosNode+Additions.h
// OMGTTT
//
// Created by Jeremy on 12/18/09.
// Copyright 2009 Jeremy Flores. All rights reserved.
//


#import "cocos2d.h"

@interface CCNode (Additions)

@property (nonatomic, readonly) CGRect rect; // dynamic
@property (nonatomic, readonly) CGPoint center; // dynamic

-(BOOL)isTouchInRect:(UITouch *)touch;

@end
43 changes: 43 additions & 0 deletions Shared/CCNode+Additions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// CocosNode+Additions.m
// OMGTTT
//
// Created by Jeremy on 12/18/09.
// Copyright 2009 Jeremy Flores. All rights reserved.
//

#import "CCNode+Additions.h"


@implementation CCNode (Additions)

@dynamic rect, center;

-(CGRect) rect
{
return CGRectMake( self.position.x - contentSize_.width*anchorPoint_.x, self.position.y-
contentSize_.height*anchorPoint_.y,
contentSize_.width, contentSize_.height);
}

-(CGPoint) center {
float x = self.rect.origin.x + self.rect.size.width/2;
float y = self.rect.origin.y + self.rect.size.height/2;
return ccp(x,y);
}

-(BOOL)isTouchInRect:(UITouch *)touch {
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
CGPoint local = [self convertToNodeSpace:touchLocation];
CGRect r = self.rect;
r.origin = CGPointZero;
if( CGRectContainsPoint( r, local ) ) {
return YES;
}
else {
return NO;
}
}

@end

0 comments on commit 6e5e8ae

Please sign in to comment.