SpriteKit Obj-C - 如何根据屏幕大小在节点上添加一定距离的力

时间:2015-11-14 15:59:58

标签: objective-c sprite-kit skphysicsbody screen-size

我有一个SKSpriteNode,我试图在屏幕上抛出一定的点。我已经尝试根据屏幕尺寸施加冲动和/或力,但这有奇怪的结果。我也尝试根据屏幕尺寸改变精灵的速度。这是我尝试过的一些代码。

- (void)createFlyingButton
{
    NSLog(@"Flying button created!");

    // Create the button.
    SKSpriteNode *button = [SKSpriteNode spriteNodeWithImageNamed:@"BlueButton"];
    button.name = @"BlueButton";
    button.size = _buttonSize;
    button.position = CGPointMake(randomInRange(self.size.width * 0.25, self.size.width * 0.75),
                                  -(_buttonSize.height * 3.0));
    button.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:_buttonSize.width * 0.5];
    button.physicsBody.collisionBitMask = 0.0;
    [self addChild:button];

    // Send it flying.
//    button.physicsBody.velocity = CGVectorMake(randomInRange(-self.size.width * 0.4, self.size.width * 0.4),
//                                               randomInRange((self.size.height * 1.6), self.size.height * 1.8));
//    [button runAction:[SKAction applyImpulse:CGVectorMake(randomInRange(-self.size.width * 0.1, self.size.width * 0.1),
//                                                          randomInRange((self.size.height * 0.8), self.size.height * 0.8))
//                                    duration:1.0]];

}

还有其他建议吗?

0 个答案:

没有答案