0
基本的に、私は点aから点bまで線を描くdrawメソッドを持つカスタムクラスを持っています。ccDrawLineをカスタムクラスの一部として使用すると、タッチを検出できますか?
私はCCSpriteをサブクラス化していますので、誰かがその行に触れたときに検出するための境界ボックスがありますか?
私が達成しようとしているものの一例として、私は一緒にこのコードを石畳ました:
- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: [touch locationInView:touch.view ]];
for (Path *path in paths) {
CGRect pathRect = CGRectMake(path.position.x, path.position.y, path.contentSize.width, path.contentSize.height);
if(CGRectContainsPoint(pathRect, location)) {
CCLOG(@"Line Touched");
}
}
}
パスは、Pathオブジェクトの変更可能な配列です。メソッドの各ステートメントの後にログを置いて、forループ以外のすべてを取得します。何らかの理由で、決してループに入り込まないようです。