Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit - Set Scale and Physics

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 across., this works as expected - increase the force it flys more, increase the density it flys less etc.

The problem i have is zooming, the only way I know to zoom out on a scene is to setScale, and the shrinks all my nodes as expected.

But then instead of the object flying the same amount (just zoomed out) it flys more than double the distance.

When I log the mass / density etc of the object before and after I scale they are the same, as expected.

So why doesn't it fly the same amount ? Tried changing the impulse to match the scale, but it doesnt work, yes it flys less distance - but its not one for one with the scaling.

Tricky question...

Thanks for ideas.

like image 839
DogCoffee Avatar asked Sep 30 '13 06:09

DogCoffee


People also ask

What is SpriteKit used for?

What is SpriteKit? SpriteKit is a powerful 2D sprite-based framework for games development from Apple. SpriteKit uses SKView which is a scene, it is the visual that you see on your screen. For those who are familiar with making iOS App, it is similar to Storyboard.

What is Apple SpriteKit?

The SpriteKit framework makes it easy to create high-performance, battery-efficient 2D games. With support for custom OpenGL ES shaders and lighting, integration with SceneKit, and advanced new physics effects and animations, you can add force fields, detect collisions, and generate new lighting effects in your games.

What is a node in SpriteKit?

Nodes: building blocks of content in the SpriteKit scenes. A node's position is determined in relationship to its parent and to its anchorPoint.


1 Answers

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.

like image 147
JKallio Avatar answered Oct 05 '22 06:10

JKallio