Object takes non-integer positions in Chrome (pix.roundg.on)

Bugs will be moved here once resolved.

Post » Sat Dec 06, 2014 9:31 pm

Problem Description
Sometimes when moving objects they don't move to integer positions. Instead they move to positions very very close to the integer one (ex. X=48 Y=48,000000001 instead of X=48 Y=48), even when the pixel rounding option is turned on. This is problematic in situations when we need to check if the X or Y of two objects are the same. This seems to happen only in Google Chrome
Attach a Capx

Description of Capx
The grey squares represent the area limit and the green square represent the player. When the player moves to the top left limit, the position it takes is not an integer one.
Steps to Reproduce Bug
  • Step 1 - Start the debug layout mode
  • Step 2 - Move the player to the top left position using the arrows
  • Step 3 - Try to move up and down along the left area edge (sometimes it takes more tries to replicate the error in IE)

Observed Result
Check that sometimes the player box takes non-integer positions

Expected Result
I expected the player to take integer positions (because the pixel rounding option is on)

Affected Browsers
  • Chrome: YES
  • FireFox: NA
  • Internet Explorer: YES

Operating System and Service Pack
Windows 8.1 64bits
Construct 2 Version ID
r190 64bits
You do not have the required permissions to view the files attached to this post.
Posts: 12
Reputation: 583

Post » Sun Dec 07, 2014 12:46 am

Closing as not a bug: 'pixel rounding' has no effect on this, since it does not affect the actual object co-ordinates, only the position when rendering the object image.

See 'Expecting math calculations to be exact' in the blog post common mis-used events and gotchas. This is a normal floating-point precision issue. If you add and subtract the X and Y co-ordinates directly, you will preserve perfect accuracy. However since you use the 'Move at angle' action, which can take any angle at all, it calculates:

x offset = cos(angle) * move distance
y offset = sin(angle) * move distance

Trigonometric functions can only return approximate results, and work with radians, so there is opportunity for rounding error in both the degrees-to-radians conversion and the calculation of a trigonometric function.
Scirra Founder
Posts: 24,371
Reputation: 193,772

Post » Sat Jan 07, 2017 5:00 am

I'm sorry if this comment isn't appropriate to post here. I'm still learning.

Is there a way to make objects snap to a grid of positions that is only integers? Can I be moving an object around when editing my game and have the object's positions be integers? I'm not talking about any browser problems, this is just me editing my game.
Posts: 13
Reputation: 2,130

Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 4 guests