Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 90 lines (76 sloc) 2.324 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
/*
* Kobold2D™ --- http://www.kobold2d.org
*
* Copyright (c) 2010-2011 Steffen Itterheim.
* Released under MIT License in Germany (LICENSE-Kobold2D.txt).
*/

#import "CCNodeExtensions.h"
#import "ccMoreTypes.h"

@implementation CCNode (KoboldExtensions)

-(BOOL) containsPoint:(CGPoint)point
{
CGRect bbox = CGRectMake(0, 0, _contentSize.width, _contentSize.height);
CGPoint locationInNodeSpace = [self convertToNodeSpace:point];
return CGRectContainsPoint(bbox, locationInNodeSpace);
}

#if KK_PLATFORM_IOS
-(BOOL) containsTouch:(UITouch*)touch
{
CCDirector* director = [CCDirector sharedDirector];
CGPoint locationGL = [director convertToGL:[touch locationInView:director.view]];
return [self containsPoint:locationGL];
}
#endif

-(BOOL) intersectsNode:(CCNode*)other
{
CGRect bbox1 = [self boundingBox];
CGRect bbox2 = [other boundingBox];
return CGRectIntersectsRect(bbox1, bbox2);
}

+(id) nodeWithScene
{
CCScene* scene = [CCScene node];
[scene addChild:[self node]];
return scene;
}

-(CGPoint) boundingBoxCenter
{
CGRect bbox = [self boundingBox];
return CGPointMake(bbox.size.width * 0.5f + bbox.origin.x, bbox.size.height * 0.5f + bbox.origin.y);
}

-(void) transferToNode:(CCNode*)targetNode
{
NSAssert(self.parent != nil, @"self hasn't been added as child. Use addChild in this case, transferToNode is only for reassigning child nodes to another node");
CCNode* selfNode = [self retain];
[self removeFromParentAndCleanup:NO];
[targetNode addChild:selfNode z:selfNode.zOrder tag:selfNode.tag];
[selfNode release];
}

-(CGSize) size
{
return CGSizeZero;
}

-(void) setSize:(CGSize)size
{
if ([self isKindOfClass:[CCLayerColor class]])
{
CCLayerColor* layer = (CCLayerColor*)self;
[layer changeWidth:size.width height:size.height];
}
}

-(void) removeChildrenInArray:(id<NSFastEnumeration>)childArray cleanup:(BOOL)cleanup
{
for (CCNode* node in childArray)
{
NSAssert1([node isKindOfClass:[CCNode class]], @"can't remove %@ because it's not a CCNode object", node);
[self removeChild:node cleanup:cleanup];
}
}

-(void) setPositionRelativeToParentPosition:(CGPoint)pos
{
    CGPoint parentAP = _parent.anchorPoint;
    CGSize parentCS = _parent.contentSize;
    self.position = ccp(parentCS.width * parentAP.x + pos.x,
parentCS.height * parentAP.y + pos.y);
}

@end
Something went wrong with that request. Please try again.