为什么生成随机精灵会产生黑屏?

时间:2015-02-16 18:07:01

标签: ios objective-c sprite-kit

我一直在尝试以下代码:

for (int i = 0; i < 5 ; i ++){
int amount = arc4random()%3;
SKSpriteNode *Obsticle;

for (i = 0; i < (amount+1); i++) {
        int position = arc4random()%2;
        int size = arc4random()%2;

        Obsticle = [SKSpriteNode spriteNodeWithColor:[UIColor purpleColor] size:CGSizeMake((size + 1)* self.scene.size.height/5, self.scene.size.height/5)];
        Obsticle.name = @"obsticle";
        Obsticle.position = CGPointMake(Obsticle.size.width/2 - self.scene.size.width/2 + position * self.scene.size.height/5, 2*self.currentY+self.scene.size.height/5);
        Obsticle.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:Obsticle.size];
        Obsticle.physicsBody.dynamic = NO;
        [world addChild:Obsticle];
    }
    self.currentY += self.scene.size.height/5;
}

代码应该在屏幕上的随机点生成各种长度块。但是,如果我在xcode上运行模拟,它只显示黑屏(我认为它不会加载,因为它不显示fps和节点数量)。任何想法如何解决它或者你现在更有效的方式来制作我刚刚尝试创建的东西?

0 个答案:

没有答案