1
\$\begingroup\$

I have an SKSpriteNode that I'm trying to throw up to a certain point on the screen. I've tried applying an impulse and/or force according to the screen size, but that has strange results. I've also tried changing the sprite's velocity according to the screen size. Here's some code I tried.

- (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]];

}

Any other suggestions?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.