我正在尝试创建一个无尽的卷轴。墙壁将从屏幕右侧以完全相同的位置但在不同的时间产生。
我遇到了一个问题,我无法移动阵列中的所有墙壁。我可以移动一个墙,但如果我尝试在阵列中移动多个生成的墙,它就会失败。有人可以看看我的代码,并告诉我哪里出错了?
提前致谢!
@interface GameScene() {
Wall* brickWall;
}
@property (nonatomic, strong) NSMutableArray *wallArray;
- (void)generateWall {
for (int i=0; i<10; i++) {
brickWall = [Wall node];
brickWall.zPosition = 2;
brickWall.position = CGPointMake(CGRectGetWidth(self.frame) * 1.1, CGRectGetHeight(self.frame) * 0.3);
[self.wallArray addObject:brickWall];
[self.wallArray addObject:brickWall];
[self addChild:brickWall];
}
-(void)update:(CFTimeInterval)currentTime {
if (self.gamePlaying == YES) {
for ( brickWall in self.wallArray) {
brickWall.position = CGPointMake(brickWall.position.x-4, brickWall.position.y);
}
}
}
@end
@interface Wall () {
SKSpriteNode* brickWall;
}
@end
@implementation Wall
-(id)init {
if (self = [super init]) {
// do initialisation
brickWall = [SKSpriteNode spriteNodeWithImageNamed:@"BrickWall"];
[self addChild:brickWall];
}
return self;
}
@end