Spritekit - 节点消失

时间:2014-04-27 11:55:35

标签: ios sprite sprite-kit

我是Stack Overflow的新手,请原谅我的高傲。

无论如何,这些假期我一直在努力开发应用程序,而且我一直在努力解决一些问题。我试图让它每两秒钟就会掉落一次,然而它会来,然后就会消失。有些人被困在顶部,而且时不时地会掉落。我制作了一段视频:https://www.youtube.com/watch?v=6eFixTM0cnM

- (id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */
        [self setupDodger];
        [self setupHUD];
        [self createRocks];
        self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];}
    return self;}

- (void)setupDodger {
    SKNode* dodger = [self makeDodger];
    dodger.position = CGPointMake(self.size.width / 2.0f, kDodgerSize.height/2.0f);
    [self addChild:dodger];}

- (SKNode*)makeDodger {
    SKNode* dodger = [SKSpriteNode spriteNodeWithColor:[SKColor greenColor] size:kDodgerSize];
    dodger.name = kDodgerName;
    dodger.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:dodger.frame.size];
    dodger.physicsBody.dynamic = YES;
    dodger.physicsBody.affectedByGravity = NO;
    dodger.physicsBody.mass = 0.02;
    dodger.physicsBody.allowsRotation = FALSE;
    return dodger;}
- (CGFloat)makeRandomXWBetween:(CGFloat)low and:(CGFloat)high {
    CGFloat randomValue = rand() / (CGFloat) RAND_MAX;
    return (randomValue *  (high - low) + low);}

- (void)addRock {
    SKSpriteNode * rock = [SKSpriteNode spriteNodeWithImageNamed:@"asteroid"];
    rock.position = CGPointMake ([self makeRandomXWBetween:0 and:self.size.width], self.size.height);
    rock.name = @"rock";
    rock.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:rock.size];
    [self addChild:rock];}

- (void)createRocks {
    SKAction * addRockAction = [SKAction sequence:
                                @[[SKAction
                                   performSelector:@selector(addRock) onTarget:self],
                                  [SKAction waitForDuration:2.0 withRange:0]]];
    SKAction * runInfinate = [SKAction repeatActionForever:addRockAction];
    [self runAction:runInfinate];}

感谢Advnace的任何帮助! 最好的祝福, 路易斯。

0 个答案:

没有答案