简体   繁体   English

如何在另一个Sprite的子Sprite上检测触摸

[英]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. 当我触摸形状的内容空间时,将出现4个红点,然后在执行ctrl + T时像在photoshop中一样调整其大小(变换)。

看起来就是这样

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 我想用cocos2d或kobold2d制作这就是我制作形状的方式

 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];

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");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM