SpriteKit iPhone/iPad different resolution, need same physics

允我心安 提交于 2019-12-18 20:54:23

问题


As I am porting an iPhone app that uses SpriteKit to iPad, I have been able to scale all the screen elements and font sizes using the height ratio of the iPhone 5 to iPad screen.

Everything looks proportional, except for the physics since there is more area.

So the question is, how do I scale the physics along with the screen using that height ratio?

Perhaps changing density or mass of all the nodes? How would I do it, mathematically using the ratio so that it is perfect?


回答1:


You can configure the SKPhysicsWorld object attached to the SKScene.
It changes:

  • The gravity property that applies an acceleration to volume-based bodies in the simulation.
  • The speed property determines the rate at which the simulation runs.

You can set those properties to values that seems good to you on an iPad. Changing the Physic World changes physics for all SKObjects.



来源:https://stackoverflow.com/questions/21791255/spritekit-iphone-ipad-different-resolution-need-same-physics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!