0

我正在寻找从另一个 Sprite 节点(敌舰)射击 SKSpritenode(炮弹)。炮弹应该从敌舰节点直接向下移动到屏幕底部。我似乎无法正确定位,炮弹似乎从屏幕的角落射击并且没有移动很远,敌舰节点是从屏幕上所有光环的数组中随机选择的,炮弹位置分配给前面的光环:

//炮弹

ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:6];
    ball.physicsBody.velocity = CGVectorMake(SHOT_SPEED, SHOT_SPEED);

    // we dont want ball to lose speed or momentum when it hots edges so..
    ball.physicsBody.restitution=1.0;  // max bounceness of node
    ball.physicsBody.linearDamping =0.0; // dont reduce linear velocity ove time
    ball.physicsBody.friction=0.0;

    ball.physicsBody.categoryBitMask = kCCBallCategory;
    // ball.physicsBody.contactTestBitMask = kCCEdgeCategory;
    ball.physicsBody.collisionBitMask= kCCEdgeCategory;
    ball.physicsBody.contactTestBitMask = kCCEdgeCategory | KCCShieldUPCategory | kCCMultiUpCategory ; // | KCCShieldUPCategory notify

// 敌舰节点数组

NSMutableArray *allHalos = [NSMutableArray array];
[_mainLayer enumerateChildNodesWithName:@"halos" usingBlock:^(SKNode *node, BOOL *stop) {
    [allHalos addObject:node];
}];




if ([allHalos count]>0) {
        NSUInteger allHalosInteger = arc4random_uniform([allHalos count]);
        SKSpriteNode *shooterHalo=[allHalos objectAtIndex:allHalosInteger];
        ball.position = CGPointMake(shooterHalo.position.x, shooterHalo.position.y - shooterHalo.frame.size.height/2 + ball.frame.size.height / 2);

        CGPoint bulletDestination = CGPointMake(shooterHalo.position.x, - ball.frame.size.height / 2);

        [self fireBullet:ball toDestination:bulletDestination withDuration:2.0 ];



    }

-(void)fireBullet:(SKNode*)ball toDestination:(CGPoint)destination withDuration:(NSTimeInterval)duration  {
    //1
    SKAction* bulletAction = [SKAction sequence:@[[SKAction moveTo:destination duration:duration],
                                                  [SKAction waitForDuration:3.0/60.0],
                                                  [SKAction removeFromParent]]];


    [ball runAction:[SKAction group:@[bulletAction, _soundLaser]]];

    [self addChild:ball];
}

任何输入表示赞赏。

4

0 回答 0