Jump to content

Don't scale physics with game resolution


tips4design
 Share

Recommended Posts

I have a game where you drop a sprite from the top part of the screen. I am using Phaser and P2JS (latest version).

 

The problem is that on PC it's working ok, but when I try on tablet, with retina dispay, the game resolution is higher, so the game height is larger. Now, if the game height is larger, means that the object is further up (being dropped from the top of the screen). This affects the time it takes to land. Also, because the resolution is higher, all objects are larger and they have different P2JS motions (different friction values, etc...).

 

How can I make sure that P2JS runs the same even if the sprites are scaled. At the moment my sprite is 1/10 of the screen height, regardless the resolution.

 

Is there any way to make the physics (P2JS) run at default resultion (non-retina) and then only display the scaled sprites?

 

I was thinking about adding all my sprites inside a group, running the physics in that group (non-retina size) and then somehow scale only the rendering of that group to match the screen resolution.

 

Any ideas?

Link to comment
Share on other sites

hmmm, just my two cents. Perhaps youre making it more difficult for yourself than needed and just go with a fixed resolution. The other alternative would be to take in the game width and height into all the physics. Sorry if im re-iterating just bouncing ideas.

Link to comment
Share on other sites

But if I used fixed canvas size I won't get retina resolution for assets. Or is it possible?

 

And I can't make the effective game area fixed (eg: game in the middle, add background for the excess size) because the sprites have to drop from the top of the screen to the bottom.

 

I will try another approapch, run my physics at fixed resolution (eg: create invisible bodies) and in the update loop map the position and sizes of those bodies to the actual screen size.

Link to comment
Share on other sites

At the moment my sprite is 1/10 of the screen height, regardless the resolution

 

You problem is that you scale the objects depending on the screen size.

Sooo, the objects don't have the same body depending the screen ... so this behavior is totally normal.

 

You should use fixed sizes for objects and work with the camera sizes.

So your game is actually the same on every device but the view would vary.

Link to comment
Share on other sites

You problem is that you scale the objects depending on the screen size.

Sooo, the objects don't have the same body depending the screen ... so this behavior is totally normal.

 

You should use fixed sizes for objects and work with the camera sizes.

So your game is actually the same on every device but the view would vary.

I just want everything scaled up. I want my objects to be bigger. For the physics to stay the same I would need a P2JS methond to also scale the mesurement unit (eg: by default 20 pixels = 1 physical meter, but after scaling i want 40pixels = 1 physical meter). This would solve all the issues :D

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...