[SOLVED] STI and STALKER-X Camera Issue

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Zorochase
Prole
Posts: 21
Joined: Sun May 21, 2017 10:40 pm
Contact:

[SOLVED] STI and STALKER-X Camera Issue

Post by Zorochase »

Hello!
I'm currently working on a platformer, and I decided to use STI to load my Tiled maps and adn's STALKER-X for my camera system. Both are excellent libraries, but there's one issue - sometimes, in scrollable maps, tiles "shift" in ways they shouldn't... here's an example:
Image
I was using a black background but I made it white so the glitch would be easier to see. This doesn't appear too often, and when it does, it only appears for a split second, but it's definitely noticeable. It occurs in both windowed and fullscreen, no matter the scale (speaking of which, I've also noticed stuttering in windowed mode, if that has any relevant effects). I've tried updating my map before and/or after the camera, that did nothing. I've tried different follow styles, nothing. I've tried modifying my timestep, and it only made the "shifting" occur more frequently. (The love.run I switched to can be found on STALKER_X's GitHub)
I'm drawing everything on a canvas of 416x256 pixels and I'm using LÖVE 0.10.2. I should also mention I'm drawing three layers - top, middle, and bottom, with the player being drawn between the middle and bottom layers. The camera is set to follow the player's x and y position.
If you've used these libraries together before and you know how to fix this kind of issue, or you just have an idea in general, your help will be appreciated! Thank you!
Last edited by Zorochase on Mon Dec 31, 2018 2:57 am, edited 1 time in total.
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: STI and STALKER-X Camera Issue

Post by pgimeno »

I haven't used these libraries, but the problem you describe is quite frequent and happens in general when drawing images in "nearest" mode.

It's a rounding problem internal to OpenGL. It typically happens when a coordinate's fractional part is near 0.5; in that case, due to calculation errors, some pixels are rounded down and some are rounded up, instead of homogeneously. The solution is to ensure that the fractional part of each pixel's coordinate is near 0 or 1. One way to achieve that is to round the coordinates at drawing time to the nearest integral one, using math.floor(coordinate + 0.5).

From what I see, STALKER-X manipulates the coordinate system, so you need to do that by changing line 105 here: https://github.com/adnzzzzZ/STALKER-X/b ... a.lua#L100 but in case the width or height of the screen/viewport can be odd, you may need to alter line 102 as well. If you use scaling, the calculation will be a bit more difficult in order to preserve smoothness. Hopefully you're not using rotation or non-integer scaling, as that can make the fractional part of pixel coordinates unpredictable.
Zorochase
Prole
Posts: 21
Joined: Sun May 21, 2017 10:40 pm
Contact:

Re: STI and STALKER-X Camera Issue

Post by Zorochase »

Well, this seems to have fixed it. Thanks again for your help! :awesome:
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
Post Reply

Who is online

Users browsing this forum: No registered users and 78 guests