How do I round a sprite's position to the nearest X pixels?

0 favourites
  • 5 posts
From the Asset Store
Vintage steam pixels for your UI! 125 unique assets in a single pack!
  • I am attempting to make a form of 2D level editor of sorts for a class in school so I can get into coding & programming. I am attempting to get the pieces to snap to the nearest multiple of X pixels so I can place things on a grid of sorts. I have a 3000, 3000 px layout and would like to get the pieces to automatically snap to say 150, 300 if placed at 143, 314, (thus the multiple would be 150) when the layout is running. After vigorous Googling and searching of the forums I have not been able to find what I need, for one reason or another.

    Any help is appreciated, even if it isn't what I need.

    Oh, and if I don't reply it is likely because I will likely only check this post if I am in school, in this class.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • round(X/150)*150

  • round(X/150)*150

    This seems to be correct, however, I cannot seem to decipher what I actually need to put in place of the "X" in that equation. Seeing as just the letter "X" is not actually something that is recognized by construct as an expression, I have to ask what you would put there.

    I initially attempted to put this equation into a "Set Position" command, so that when the sprite is created it's position is snapped to the nearest viable location, but as I said, the letter "X" is not supported as part of the equation.

    I'm just a bit confused on as to what you suggested I put in the location of the X. Sorry if it's something obvious, but I am still fairly new to this.

  • 'X' is the current position. You'd do the same for 'Y'.

    For SetPosition: round(Self.X/150)*150, round(Self.Y/150)*150

  • Thank You Very Much!

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