SpriteNodes在碰撞时随机消失

时间:2015-06-15 04:40:33

标签: ios sprite skspritenode

我正在创建一个类似于俄罗斯方块的iOS iPhone游戏,其中的块从天而降并相互叠加。但是,当一个块出现在另一个块之上时,我的SpriteNodes块有时会随机消失。

这是我的块放置,我将其称为10次迭代以放置掉落的随机块:

-(void)setupBlocksForT:(float)time {

    Block *block = (Block *)[SKSpriteNode spriteNodeWithImageNamed:@"block1"];
    block.physicsBody = [SKPhysicsBody bodyWithTexture:block.texture size:block.size];
    block.physicsBody.dynamic = YES;
    block.physicsBody.allowsRotation = NO;
    block.physicsBody.usesPreciseCollisionDetection = YES;
    block.physicsBody.restitution = 0;
    block.physicsBody.friction = 1.0;
    block.physicsBody.categoryBitMask = BlockMask;
    block.physicsBody.collisionBitMask = CharacterMask | GroundMask | BlockMask;
    block.physicsBody.contactTestBitMask = BlockMask | CharacterMask;

    double randomSize = rand_range_double(0.10, 0.5);
    block.xScale = randomSize;
    block.yScale = randomSize;

    block.position = CGPointMake(rand_range_int(0, self.frame.size.width, self.frame.size.height);

    SKAction *wait = [SKAction waitForDuration:1.5 * time];
    SKAction *spawn = [SKAction runBlock:^{
        [self.myWorld addChild: block];

    }];

    SKAction *spawnSequence = [SKAction sequence:@[wait, spawn]];

    [self runAction:spawnSequence];
}

我的代码中没有任何地方可以调用remove(节点)。

我正在使用SpriteKit进行开发,我的设置有一个包含所有块的SKNode,以便摄像机专注于我在DidSimulatePhysics()方法中的角色位置。

有没有人遇到他们的精灵随机消失的问题?

0 个答案:

没有答案