imprecise x and y positions causes glitches

Discussion and feedback on Construct 2

Post » Thu Sep 10, 2015 2:04 pm

Hello!

I'm working on a platformer game and have discovered a problem. When running the game in debug I saw that object does not have an exact position. example: The floor is placed with an Y position of 128 but when I inspect it in debug it has an y position of 127.9541354174. This causes annoying glitches in the player(set to be global) animations when switching to next layout, the falling animation is played for a fraction of a second before returning to normal because the floor in the next layout is also set with y value but not the same as the first one. Why is C2 setting the floor to 127.9541354174 instead of 128?
B
33
S
10
G
6
Posts: 259
Reputation: 6,801

Post » Thu Sep 10, 2015 2:16 pm

I never had such problem so I'm not very familiar with this topic, but the first thing that came to my mind was pixel rounding project property. Do you have it ON?

From the manual:
Pixel rounding
By default Construct 2 objects can be drawn at sub-pixel positions, e.g. (100.3, 200.8). If the browser is using linear filtering, this can make fine pixel art appear blurry. If Pixel rounding is set to On, Construct 2 objects round their position to a whole number before drawing, e.g. (100, 201). This prevents any blurring, and can also prevent "seams" appearing on grids of objects. Note this does not affect their actual X and Y co-ordinates, which can still be between pixels - it only affects where they are drawn on the screen.


https://www.scirra.com/manual/66/projects
ImageImageImage
B
31
S
19
G
82
Posts: 1,038
Reputation: 46,205

Post » Thu Sep 10, 2015 2:22 pm

BackendFreak wrote:I never had such problem so I'm not very familiar with this topic, but the first thing that came to my mind was pixel rounding project property. Do you have it ON?

From the manual:
Pixel rounding
By default Construct 2 objects can be drawn at sub-pixel positions, e.g. (100.3, 200.8). If the browser is using linear filtering, this can make fine pixel art appear blurry. If Pixel rounding is set to On, Construct 2 objects round their position to a whole number before drawing, e.g. (100, 201). This prevents any blurring, and can also prevent "seams" appearing on grids of objects. Note this does not affect their actual X and Y co-ordinates, which can still be between pixels - it only affects where they are drawn on the screen.


https://www.scirra.com/manual/66/projects


Yes Pixel rounding is on (using the retro style template)
B
33
S
10
G
6
Posts: 259
Reputation: 6,801

Post » Thu Sep 10, 2015 4:10 pm

Done some more testing. Found out that objects with physics behaviour, even if set to immovable renders the pixel rounding option useless. So I turned of physics for the floor but the glitch was still there, turns out that the players platform behaviour also is part of the problem since it never lands with a whole number on the Y axis. So anything with any kind of movement behavior completely disregards pixel rounding.
B
33
S
10
G
6
Posts: 259
Reputation: 6,801

Post » Thu Sep 10, 2015 4:23 pm

You have two options.
Either snap the objects to whole numbers using events.
Or don't check exact coordinates, check if it's within an area. ><
Image ImageImage
B
172
S
50
G
182
Posts: 8,439
Reputation: 115,097

Post » Thu Sep 10, 2015 4:38 pm

It is problematic in did, and definitely happens when game is upscale, but not sure if the problem exists if displayed in original window.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

Post » Thu Sep 10, 2015 4:41 pm

newt wrote:You have two options.
Either snap the objects to whole numbers using events.
Or don't check exact coordinates, check if it's within an area. ><


Can you give a short explanation on how to snap positions?
B
33
S
10
G
6
Posts: 259
Reputation: 6,801

Post » Thu Sep 10, 2015 5:20 pm

For a grid its:
int(self.x/n)*n
Where n is the nearest number to snap to.

Otherwise just use set x to int(self.x)
Image ImageImage
B
172
S
50
G
182
Posts: 8,439
Reputation: 115,097

Post » Thu Sep 10, 2015 6:06 pm

newt wrote:For a grid its:
int(self.x/n)*n
Where n is the nearest number to snap to.

Otherwise just use set x to int(self.x)


Thanks! :)
B
33
S
10
G
6
Posts: 259
Reputation: 6,801


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 3 guests