更新时间:2023-02-01 22:59:23
这看起来是一个非常困难的方式去做。我没有自己编码长,但也许以下可能会帮助你。
让说有一个名为敌人的nsmutablearray,当你创建一个新的敌人对象添加到这个数组。敌人对象将是一个ccnode,并有一个ccsprite在其中调用_enemySprite
然后触摸
That looks like a very difficult way to go about doing it. I havent been coding long myself but maybe the following might help you. lets say u have a nsmutablearray called enemies and you add the new enemy object to this array when ever you create one. enemy object would be a ccnode and have a ccsprite within it called _enemySprite then do the touch
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches];
UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
//UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
int arraysize = [enemies count];
for (int i = 0; i < arraysize; i++) {
if (CGRectContainsPoint( [[[enemies objectAtIndex:i] _enemySprite] boundingBox], location)) {
//some code to destroy ur enemy here
}
}
// NSLog(@"TOUCH DOWN");
}
希望这有助于