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

0 favourites
  • 3 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)