SpriteKit: Keep consistent sizes and speeds across devices

TL DR: I want to find a way to give an impulse to an object so that the speed of this object is exactly proportional to the size of the scene.

I am currently creating a SpriteKit game that will be available on different screen sizes. My scene resizes to be the same size in pixels as its view ( scene.scaleMode = .ResizeFill), when I ran my game on other devices, the one I developed noticed:

  • The size of the nodes was too small.

  • The speed of the objects was too low (the way I give speed to my objects is a challenge applyImpulse(:_)in the physical body).

I think I fixed the size problem with simple proportionality: I looked at the objectArea / sceneArea ratio of the scene that had the correct size for the object, and instead of giving fixed sizes to my objects, I just gave them measurements so the ratio is always the same regardless of the area of ​​the scene.

For the speed of the object it was more difficult ...
At first I thought that this was due to the fact that the mass of the physical body is higher, since the object itself is larger, but since I attributed the objects to my mass directly through their mass property, the objects would have the same mass regardless of their size.

I finally realized that just because the screen size is different from this, an object, even moving at the same speed, will move slower on a larger screen.

, , , , - :

force = sqrt(area) * k

k , , ( ).

, . , , ,

, , ?

+4
1

.

. (, , ,...), .

, , , iPad Pro iPhone 5, -.

scaleMode aspectFill (, Xcode 7: aspectFill). , , .


@Knight0fDragon , . , .

+5

Source: https://habr.com/ru/post/1652924/


All Articles