user2434837
user2434837

Reputation: 61

How to detect touch on a sprite that is a child of another sprite

I searched and found some question like mine, but there's no answer right what I need.I want to do something like this in my app. When I touch in the content space of a shape, 4 red dots will appear, then allow to resize(transform) it like in photoshop when we do ctrl+T.

This is how it looks

This is how it looks

I don't know how to detect whenever touch on a red dot and then transform it. Anyone explain me how to do this or example code.

I want to make it in cocos2d or kobold2d This is how I make my shape

 DragSprite *sprite = [DragSprite spriteWithFile:@"SpriteBGAlpha1.png" rect:CGRectMake(point.x, point.y, 100, 100)];
sprite.position = point;
sprite.color = ccRED;
[shapeArray addObject:sprite];
[self addChild:sprite z:0 tag:1];

CCSprite *s = [CCSprite spriteWithFile:@"Shape-Icon_Elevation-Triangle.png"];
s.position = ccp(sprite.boundingBox.size.width/2, sprite.boundingBox.size.height/2);
[sprite addChild:s];

dotBlueArea1 = [CCSprite spriteWithFile:@"bluedotimage.png"];
dotBlueArea1.position = ccp(0, 0);
[shapeArray addObject:dotBlueArea1];
[sprite addChild:dotBlueArea1 z:10 tag:1];

Upvotes: 1

Views: 136

Answers (1)

Chocolate..
Chocolate..

Reputation: 39

try this one..

CGPoint location = [touch locationInView: [touch view]];

location = [[CCDirector sharedDirector] convertToGL: location];

CGPoint convertedNodeSpacePoint = [aMainSpr convertToNodeSpace:location];
if (CGRectContainsPoint([child_Sprite boundingBox],convertedNodeSpacePoint))
{
NSLog(@"Touch");
}

Upvotes: 1

Related Questions