如何访问精灵数组中的第一个精灵并将其位置更改为此?
sprite.position = CGPointMake(arc4random_uniform(self.frame.size.width), arc4random_uniform(self.frame.size.height));
@property (nonatomic, strong) SKSpriteNode *aSprite;
@property (nonatomic) NSMutableArray *sprites;
一个用于精灵的一个数组来保存它们
答案 0 :(得分:2)
要访问精灵数组中的第一个对象,您可以执行以下操作:
SKSpriteNode *object = [myArray firstObject];
object.position = CGPointMake(arc4random_uniform(self.frame.size.width), arc4random_uniform(self.frame.size.height));
要访问数组中的所有对象,请执行以下操作:
for(SKSpriteNode *object in myArray) {
object.position = CGPointMake(arc4random_uniform(self.frame.size.width), arc4random_uniform(self.frame.size.height));
}