SpriteKit - Set Scale and Physics

后端 未结 3 1078
庸人自扰
庸人自扰 2020-12-09 12:38

What is the correct way to \"zoom out\" on your scene.

I have an object that I apply an impulse to fire it across the screen. It for example will fire about 100 px a

相关标签:
3条回答
  • 2020-12-09 12:53

    For those like me who ended up here after a search, changing the scale of the scene to zoom out no longer works. Instead, encapsulate all your nodes in an empty SKNode and run actions on this one:

    self.rootNode = [SKNode node];
    // Add your children nodes here to the rootnode.
    [self addChild:self.rootNode];
    // Zoom out
    [self.rootNode runAction:[SKAction scaleBy:2 duration:5]];
    // Zoom in
    [self.rootNode runAction:[SKAction scaleBy:.5 duration:5]];
    

    self is the SKScene. I hope this helps.

    0 讨论(0)
  • 2020-12-09 12:57

    I believe you're not supposed to scale the SKScene (like it hints you if you try setScale method with SKScene). Try resizing it instead.

    myScene.scaleMode = SKSceneScaleModeAspectFill;
    

    And then while zooming:

    myScene.size = CGSizeMake(myScene.size.width + dx, myScene.size.height + dy);
    

    *Apple documentation says:

    Set the scaleMode property to SKSceneScaleModeResizeFill. Sprite Kit automatically resizes the scene so that it always matches the view’s size.

    0 讨论(0)
  • 2020-12-09 13:00

    The easy fix (thanks to Chris LaPollo, an author on RW)

    [self runAction:[SKAction scaleTo:0.5 duration:0]];
    

    Nothing else needed.

    The odd thing is you cannot do

    [self setScale:0.5];
    

    As you get this warning, and it doenst work - but running an action does -- weird!!!

    SKScene: Setting the scale of a SKScene has no effect.

    0 讨论(0)
提交回复
热议问题