所以我现在认为我已经将这些精灵节点设置得很好并且它们应该出现但我无法弄清楚为什么它们没有出现在模拟器中。背景图像(bg.png)和“鸟”节点都出现,但spawnPipes方法中的节点都没有出现。我很想使用SpriteKit,所以它可能是显而易见的。
Sprite节点方法:
-(void)spawnPipes;
{
int random = (arc4random() % (int)self.frame.size.height-150)+250;
//Add pipe end
SKSpriteNode *upperPipe = [SKSpriteNode spriteNodeWithImageNamed:@"goldend.png"];
upperPipe.size = CGSizeMake(70, 25);
upperPipe.position = CGPointMake(450, random);
//Add pipe middles
SKSpriteNode *lowerPipe = [SKSpriteNode spriteNodeWithImageNamed:@"goldend.png"];
lowerPipe.size = CGSizeMake(70, 25);
lowerPipe.position = CGPointMake(upperPipe.position.x, upperPipe.position.y-150);
//Rest below
SKSpriteNode *restBelow = [SKSpriteNode spriteNodeWithImageNamed:@"goldmiddle.png"];
restBelow.size = CGSizeMake(60, lowerPipe.position.y);
restBelow.position = CGPointMake(lowerPipe.position.x, lowerPipe.position.y-restBelow.size.height/2-lowerPipe.size.height/2+1);
//Rest above
SKSpriteNode *restAbove = [SKSpriteNode spriteNodeWithImageNamed:@"goldmiddle.png"];
restAbove.size = CGSizeMake(60, self.frame.size.height+upperPipe.position.y);
restAbove.position = CGPointMake(upperPipe.position.x, upperPipe.position.y+restAbove.size.height/2+upperPipe.size.height/2-2);
[self addChild:upperPipe];
[self addChild:lowerPipe];
[self addChild:restBelow];
[self addChild:restAbove];
[pipeArray addObject:upperPipe];
[pipeArray addObject:lowerPipe];
[pipeArray addObject:restBelow];
[pipeArray addObject:restAbove];
}
然后在initWithSize中调用:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
//Bird
bird = [SKSpriteNode spriteNodeWithImageNamed:@"Godcrop.png"];
bird.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
bird.size = CGSizeMake(30, 30);
bird.zPosition = 3;
bird.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:bird.frame.size];
bird.physicsBody.usesPreciseCollisionDetection = YES;
bird.physicsBody.mass = 0.2;
bird.physicsBody.affectedByGravity = NO;
bird.physicsBody.dynamic = YES;
[self addChild:bird];
//Background
bg = [SKSpriteNode spriteNodeWithImageNamed:@"bg.png"];
bg.position = CGPointMake(160, 284);
bg.size = CGSizeMake(self.frame.size.width, self.frame.size.height);
[self addChild:bg];
//Spawns pipes
[self spawnPipes];
//Set touch boolean for touches began methods
firstTouch = YES;
}
return self;
}