How do I snap to closest grid?

Get help using Construct 2

Post » Mon Oct 12, 2015 1:09 pm

Hey everyone,

I need a bit of help here. Been changing around the values for a bit but I can't seem to get the blocks to snap to grid. I want it to snap to the closest grid when "Is not Touching" or overlapping boundary/other blocks.

I have attached the capx so hopefully someone can enlighten me.

https://www.dropbox.com/s/3b3mz92qh3t0u ... .capx?dl=0

Thanks.
B
23
S
10
G
2
Posts: 104
Reputation: 3,071

Post » Mon Oct 12, 2015 2:10 pm

Unfortunately I can't open your project, but I'm guessing you mean something like this:
x = int(object.X/32)*32
The above will set object to the closest multiple of 32.
The idea here is that the value, object.X will be divided by the grid size you want, and then rounded up/down or in this case to the closest whole number, then multiplied by the grid size again to get it back to it's proper size. In effect, it rounds to the grid size, since when int() is applied to it at a 32nd the size, it's rounding to 32x the normal size. Or something.
B
42
S
14
G
3
Posts: 165
Reputation: 5,115

Post » Mon Oct 12, 2015 2:23 pm

seems like you have offset the grid by 44px because of the border..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Oct 12, 2015 2:33 pm

You can also do this:

Value-(Value%GridValue)
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Mon Oct 12, 2015 10:56 pm

@LittleStain

The offset did the trick.

@jojoe

I'm using Value-(Value%GridValue) and it works.

Thanks guys.
B
23
S
10
G
2
Posts: 104
Reputation: 3,071

Post » Mon Oct 12, 2015 11:09 pm

mrneko wrote:@LittleStain

The offset did the trick.

@jojoe

I'm using Value-(Value%GridValue) and it works.

Thanks guys.


Well, I sure wish someone would explain to me how the heck it works.

WTF, does the "%" thing do anyway? I Just stole the idea from a StackOverflow post.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Tue Oct 13, 2015 1:58 am

@jojoe
% gives you the remainder after a division.
Ex
5%5=0
4%5=4
15%5=0
33%5=3
B
94
S
33
G
113
Posts: 5,353
Reputation: 73,267

Post » Tue Oct 13, 2015 3:05 am

@R0J0hound, thanks!

Looks like a really useful tool.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985


Return to How do I....?

Who is online

Users browsing this forum: Lisa999, RandomlyMooN and 8 guests