MAke it snap to a 32x32 grid |
I'm assuming "it" is some Sprite.
This is a simple math problem. You have an input position... and an output position. The output position is just the input position snapped to a grid. So now... the question becomes... what is the math that we can perform on the input to produce that output?
When faced with these kinds of problems, I try to find the pattern by laying out a bunch of different inputs and seeing what I would want the output to be:
INPUT - OUTPUT
______________
0 0
1 0
2 0
...
30 0
31 0
32 32
33 32
34 32
...
62 32
63 32
64 64
65 64
...
etc
|
Is this the output you want? If it is... think about what math you can do on the input to produce that output.
when i click left on the mouse, have it draw something. |
You want to seperate logic code from drawing code. When it is time to do your drawing, you should already know everything you want to draw... and where you want to draw it.
Doing something when you left click is logic code.
Drawing something is drawing code.
So we want to split these up into two separate parts. First... when the user clicks... change some variable or something. Then, when you draw, you can look at the contents of that variable or whatever to see whether or not to draw the object in question.
Oh I see, so how would i calculate a grid? |
This question is oddly worded =P
I'm going to assume you're asking the same thing as what I'm already covering above.