Snap to grid demo....help
hey everyone,
I am starting to work on my project and i have used the snap to grid advanced demo to get me started. But i need your help;
My actor is 36x36 in size and i want the grid to be the full size of the screen. What will i need to change the following attributes to achieve this. I have been fiddling around with this for ages. ANY HELP?
Here are my attributes;
![Photobucket](/home/leaving?target=http%3A%2F%2Fi1148.photobucket.com%2Falbums%2Fo566%2Fbarkingapps%2FScreenShot2012-06-18at184124.png)
BarkingApps :o3
Cut the Rope INTERFACE Flight Control INTERFACE Contact: barkingapps@gmail.com
I am starting to work on my project and i have used the snap to grid advanced demo to get me started. But i need your help;
My actor is 36x36 in size and i want the grid to be the full size of the screen. What will i need to change the following attributes to achieve this. I have been fiddling around with this for ages. ANY HELP?
Here are my attributes;
![Photobucket](/home/leaving?target=http%3A%2F%2Fi1148.photobucket.com%2Falbums%2Fo566%2Fbarkingapps%2FScreenShot2012-06-18at184124.png)
BarkingApps :o3
Cut the Rope INTERFACE Flight Control INTERFACE Contact: barkingapps@gmail.com
Best Answer
-
lukey5227 Posts: 111
I think something like this might be a little easier:
Take the width of the screen and divide it by either how long you want each box (to figure out the number) or divide it by the number you have along (to figure out the length). Do this also for the height.
So now you know its an x by y grid. These numbers multiplied by your with should give your screen length. Its smart to subtract one from each of these so you can adding padding to the bottom and sides when you're done.
Something has position x of a (low number) and position y of b (another low number). Suppose you need to move it one space down since the user pressed "S". All you need to do is subtract 1 from b. If b was 5, its now 4.
Lets jump to a and b now. We're going to constrain the position x of this object to "padding + (a*cell_width))" and the same for position y but with height and b.
constrain a "max(min(Highest value,a),Lowest value)
Max takes the highest value of the 2 shown like this: max(4,6). This displays 6. Min is the opposite. min(4,6) displays 4 since thats the lowest value.
Here, we have max and min inside each other so we can have a range. This prevents the user from going out of bounds. To calculate, for example, the maximum height (min since we need the lowest value), we just multiply the length in small numbers by the cell length plus some padding. We don't need to put in any straight numbers at all!
Finally, we need to make sure that a and b don't go under or over the max numbers.
So lets simulate everything real quick so you understand what this all means.
The user presses the A key. That means left. subtract 1 from a. Constraining prevents it from going under 0. If the actor is at 4, this means its now at "a" of 3. Now, multiply 3 by 55 (165) and add the padding (lets say its 55/2). 27.5 + 165 = x position of it.
No delta x, no delta y, no confusing bottom and top limit (even though you can still add those in).
If you get everything I'm saying: should take you 5 minutes.
If you don't get everything I'm saying: reference me with @luke5227 and tell me what you can't understand or email me at luke5227@gmail.com
- luke5227. Hope I could help!
Answers
BarkingApps :o3
Cut the Rope INTERFACE Flight Control INTERFACE Contact: barkingapps@gmail.com