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

Get help using Construct 2

» Wed Jan 04, 2017 6:33 pm

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.
Last edited by Justin Kennedy on Wed Jan 04, 2017 6:58 pm, edited 1 time in total.
B
3
Posts: 3
Reputation: 181

» Wed Jan 04, 2017 6:50 pm

round(X/150)*150
B
72
S
22
G
288
Posts: 3,862
Reputation: 158,460

» Thu Jan 05, 2017 6:00 pm

blackhornet wrote: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.
B
3
Posts: 3
Reputation: 181

» Thu Jan 05, 2017 6:45 pm

'X' is the current position. You'd do the same for 'Y'.
For SetPosition: round(Self.X/150)*150, round(Self.Y/150)*150
B
72
S
22
G
288
Posts: 3,862
Reputation: 158,460

» Thu Jan 05, 2017 6:57 pm

Thank You Very Much!
B
3
Posts: 3
Reputation: 181