【发布时间】:2014-05-16 20:42:45
【问题描述】:
我有一个 Sprite Kit 小游戏,屏幕上有薮蚂蚁,当你触摸它们时,它们应该会消失。
这是我添加蚂蚁的代码:
-(void)addAnt
{
SKSpriteNode *ant = [SKSpriteNode spriteNodeWithImageNamed:@"ant-icon"];
NSString *antName = [NSString stringWithFormat:@"ant %d",_antNumber];
_antNumber++;
ant.name = antName;
ant.xScale = 0.5;
ant.yScale = 0.5;
int lowestPositionX = ant.size.width/2;
int highestPositionX = self.size.width - ant.size.width/2;
int lowestPositionY = ant.size.height/2;
int highestPositionY = self.size.height - ant.size.height/2;
int randomSpiderXValue = lowestPositionX + arc4random() % (highestPositionX - lowestPositionX);
int randomSpiderYValue = lowestPositionY + arc4random() % (highestPositionY - lowestPositionY);
int randomRotaionValue = -2*M_PI + arc4random() % (int)(2*M_PI - 2*-M_PI);
ant.zRotation = randomRotaionValue;
ant.position = CGPointMake(randomSpiderXValue, randomSpiderYValue);;
[self addChild:ant];
}
然后,当屏幕被触摸时,我想删除被触摸的蚂蚁。 (蚂蚁 %d)。 我怎样才能遍历所有的蚂蚁并删除触摸过的蚂蚁?
【问题讨论】:
-
你对触摸做出反应的代码是什么?
标签: ios objective-c sprite-kit