0

別のスプライト ノード (敵船) から SKSprite ノード (砲弾) を撃ちたいと思っています。砲弾は、敵の船のノードから画面の下部に向かってまっすぐ下に移動する必要があります。位置を正しく設定できないようです。砲弾は画面の隅から発射され、遠くまで移動しないようです。敵船ノードは、画面上のすべてのハローの配列から一度にランダムに選択され、砲弾の位置がそのノードに割り当てられます。ハローの前面:

// 大砲

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