Large Y Position Causes Rendering Issues iOS (SOLVED)

Hello,

I’m loving Defold so far. I just stumbled across a weird bug that is making my game unplayable on iOS.

My game is a vertical scroller with the player starting ~100 y position with that increasing throughout the game. The camera follows the player, so the player and all the game objects have higher and higher y positions as the game goes on. On my Macbook with both Bundle and Bundle as HTML, the game works excellent. When I Bundle for iOS and install on my phone or target my iPhone directly, this is where it gets interesting. Around 10,000 y, the game starts stuttering on iOS. Around 50,000 y or so, sprites start to render a little warped (like bigger than expected), then around 200,000 y half of my sprites don’t render at all and the others are very warped.

I ran Instruments in XCode and CPU is like 15-20%, memory is consistent at 25MB, no leaks, and GPU shows 59-60 FPS the entire time.

To make sure it wasn’t my game logic, I changed my game starting y position to 200,000, and sure enough even at the start of the game sprites are missing / warped. It seems like it is only a factor of the y position. Starting the game at 200,000 on my Macbook, everything renders fine, so it appears to be only iOS (and I haven’t tested on Android yet but I will).

My general question is - is there some sort of limit to the y position of my world? I could refactor my game so that the player doesn’t move and instead platforms move in an out of the screen so that the y position never exceeds ~2000, but that would involve a lot of refactoring so I don’t want to do that yet.

Thanks,
Dan

I’d guess you need to make a custom copy of the materials and change to high precision for the shader programs.

Another option is to move everything in the entire game world down some every 1k distance from origin.

2 Likes

Like Pkeod writes it’s a matter of precision in the shaders. Increasing the precision will make the problem go away, at least for a while. Search the forum for examples of how to do this. Your solution of moving everything else is better though. Put everything that should move parented to a root game object and move that object.

2 Likes

Thank you both for the suggestions! That’s a good idea to move a parent object, I’ll give that a try.

[UPDATE] Moving everything down periodically worked perfectly - great idea!

3 Likes

Although we use Lua, which uses double precision floats, internally, our math library uses floats (IEEE 32 bit precision). On top of that, OpenGL ES supports various precision modes: lowp, mediump and highp, each which clamp the values to their respective range.

Remember, neither floats nor doubles give you infinite precision! :slight_smile:

3 Likes