【发布时间】:2017-05-21 15:19:34
【问题描述】:
是否可以在-(void)update:(CFTimeInterval)currentTime 方法中从同一个SKSpriteNode 获得2 个位置?
我正在做一个演示。从屏幕外的随机点射出一个球。我想得到球的方向和位置数组,以便我可以根据它做一些事情。但是当我使用update: 方法时,它似乎在每次更新中填充了数组。如何每次更新只添加一个SKSpriteNode 到数组中?
NSMutableArray *nodePos;
int returnPosCount;
-(void)update:(CFTimeInterval)currentTime {
if ([self childNodeWithName:@"//ball"]!=nil){
returnPosCount++;
if (returnPosCount == 15) {
SKNode *node = [self childNodeWithName:@"//ball"];
[nodePos addObject:node];
if ([nodePos count]>4) {
[nodePos removeObjectAtIndex:0];
NSLog(@"%@",nodePos);
}
returnPosCount =0;
}
NSLOG:
<SKSpriteNode> name:'ball' (64 x 64)] position:{-127.63968658447266, 135.19813537597656}
<SKSpriteNode> name:'ball' (64 x 64)] position:{-127.63968658447266, 135.19813537597656}
<SKSpriteNode> name:'ball' (64 x 64)] position:{-127.63968658447266, 135.19813537597656}
【问题讨论】: