-1

I created an impulse:

impulse = frame.size.height/18

and gravity:

self.physicsWorld.gravity = CGVectorMake(0.0, -2.85)

and I use this code to apply the impulse to the player:

hond.physicsBody?.applyImpulse(CGVectorMake(0, impulse))

Now when I test it on the simulator, the player jumps higher on the iPhone 5s simulator and lower on the iPhone 6 or iPhone 6 plus simulator.

Why is this happening and how can I fix this?

sangony
  • 11,636
  • 4
  • 39
  • 55
sdd
  • 889
  • 8
  • 29
  • 1
    I think your problem is how you calculate the impulse. iPhone 5s screen is smaller than iPhone6/6s screen, so frame.size.height/18 will be different in each case – EnriMR Apr 24 '15 at 13:27
  • Thank you but didn't help, see my answer to Dean – sdd Apr 24 '15 at 13:33
  • You can use the vijeesh code to detect each device and personalize the impulse value – EnriMR Apr 24 '15 at 13:38

2 Answers2

2

Your impulse is impulse = frame.size.height/18 depends of the height of the screen. But iPhone 6 and 6 plus have a bigger height than iPhone with a 4 inches screen.

This is why your player jump higher.

Dean
  • 1,512
  • 13
  • 28
  • In your case the player should jump higher with the iPhone 6 plus, but it jumps lower. I changed impulse to: impulse = 18. still the iPhone 5s jumps higher than 6 and 6 plus.. – sdd Apr 24 '15 at 13:32
  • Maybe the rest of your scene is also dependent of screen sizes ? If decor element depend of the size of the screen, then a fixed impulse won't help to have the same jump for every device – Dean Apr 24 '15 at 13:46
  • Thats right, rest of scene is dependent of screen sizes. is there any easier way to define the impulse instead of tracing which device is being used? – sdd Apr 24 '15 at 13:54
  • You can define the impulse dependent to the size of an obstacle for example ? With the right coefficient, it should be reliable. – Dean Apr 24 '15 at 14:40
0

Here's the updated version of https://gist.github.com/1323251

https://github.com/froztbytes/UIDeviceHardware

This will help you to find the device on which the app is currently running. Code according to the device and you can fix your issue

vijeesh
  • 1,317
  • 1
  • 17
  • 32
  • I implemented it in my project, but when I build it gives this error; use of undeclared identifier "UIDevice", pointing to the .m file – sdd Apr 24 '15 at 13:39
  • See the source code, this is only for simulator, in a real case you are not going to need to detect i386 or x86_64. Just return different value for each. – EnriMR Apr 24 '15 at 13:55