我正在使用SpriteKit构建游戏。 以下是我坚持的地方。
我将SKSpriteNode放置在场景中并通过递减它的X位置来更新它的位置
- (void)update:(NSTimeInterval)currentTime
方法
但是当节点到达X:594时,它就停留在那里。并没有移动后记。 我不明白为什么会这样。
这是我正在使用的SKSPriteNode,其中单独的类为“BirdNode”
@property (strong,nonatomic) SKAction * flap;
@property (strong,nonatomic) SKAction * flapForever;
- (id)initWithImages:(NSArray *)images
{
if(self = [super init]) {
NSMutableArray *textures = @[].mutableCopy;
for (NSString *imageName in images) {
SKTexture* birdTexture = [SKTexture textureWithImageNamed:imageName];
birdTexture.filteringMode = SKTextureFilteringNearest;
[textures addObject:birdTexture];
}
DebugLog(@"Textures = %@",textures);
self = [BirdNode spriteNodeWithTexture:[textures objectAtIndex:0]];
self.flap = [SKAction animateWithTextures:textures timePerFrame:0.02];
self.flapForever = [SKAction repeatActionForever:self.flap];
[self setTexture:[textures objectAtIndex:0]];
[self setPhysicsBody:[SKPhysicsBody bodyWithRectangleOfSize:self.size]];
[self.physicsBody setCategoryBitMask:obstacleBitMask];
[self.physicsBody setContactTestBitMask:playerBitMask];
[self.physicsBody setDynamic:YES];
[self runAction:self.flapForever withKey:@"flapForever"];
return self;
}
+ (NSArray *)birdImages:(int)number {
NSMutableArray *birds = @[].mutableCopy;
for (int i = 0; i < 25; i ++) {
NSString *birdImage = @"";
birdImage = [birdImage stringByAppendingFormat:@"flying_bird%d",number];
birdImage = [birdImage stringByAppendingString:(i+1)<10?@"0":@""];
birdImage = [birdImage stringByAppendingFormat:@"%d",i+1];
[birds addObject:birdImage];
}
return birds;
}
在Scene中添加上述SPriteNode。
BirdNode *bird = [[BirdNode alloc] initWithImages:[BirdNode birdImages:1]];
bird.anchorPoint = CGPointZero;
bird.physicsBody.categoryBitMask = obstacleBitMask;
bird.physicsBody.contactTestBitMask = playerBitMask;
bird.physicsBody.dynamic = YES;
bird.name = @"Bird";
bird.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:bird.size];
bird.position = CGPointMake(1000, 240);
[self addChild:bird];
[Nodes addObject:bird];
这是我更新Node的位置的方法。
- (void)update:(NSTimeInterval)currentTime
{
[self updateNodes:currentTime];
}
- (void) updateNodes:(NSTimeInterval)currentTime
{
//Here nbNodes = [Nodes count];
for(int i = 0; i < nbNodes; i ++) {
BirdNode *bird = Nodes[i];
bird.position = CGPointMake(bird.frame.origin.x - 3, bird.frame.origin.y);
}
}
但是,当一只鸟从1000到达X位置594时卡住了。 黑客攻击我做错了什么。 如何解决这个问题。
请帮帮我。