I want to create touch areas (CGMutablePathRefs) around my hexagon sprites. My aim is creating keys with names hexTouchArea1, hexTouchArea2, and so on, so I started to store them in an NSMutableDictionary. But I can't store CGMutablePathRefs in it. How would I solve the problem ?
for (int i = 0; i < hexCount; i++) {
hexTouchAreas = [[NSMutableDictionary alloc] init];
CGPoint touchAreaOrigin = ccp(location.x -22, location.y-40);
NSString *touchAreaKey = [NSString stringWithFormat:@"hexTouchArea%d",i];
CGMutablePathRef hexTouchArea = CGPathCreateMutable();
hexTouchArea = [self drawHexagonTouchArea:touchAreaOrigin];
[hexTouchAreas setObject:hexTouchArea forKey:touchAreaKey];
NSLog(@"the touchareas are %@", hexTouchAreas);
}
drawHexagonTouchArea returns a CGMutablePathRef :
-(CGMutablePathRef) drawHexagonTouchArea:(CGPoint)origin
{
CGMutablePathRef path = CGPathCreateMutable();
CGPoint newloc = CGPointMake(origin.x, origin.y);
CGPathMoveToPoint(path, NULL, newloc.x, newloc.y);
CGPathAddLineToPoint(path, NULL, newloc.x -22,newloc.y + 38);
CGPathAddLineToPoint(path, NULL, newloc.x + 0, newloc.y + 76);
CGPathAddLineToPoint(path, NULL, newloc.x + 46, newloc.y + 76);
CGPathAddLineToPoint(path, NULL, newloc.x +66,newloc.y + 40);
CGPathAddLineToPoint(path, NULL, newloc.x +44, newloc.y + 0);
CGPathCloseSubpath(path);
return path;
}
AND : How can I assign these touch areas to CCSprites so if the sprite rotates, they do not move separately ?