Need help rotate many objects
by Danny Mejia · in Torque Game Builder · 08/19/2006 (6:06 pm) · 1 replies
I have 16 object like this:
****
****
****
When I click on one of the objects I want the other object that thouch it to rotate. So If I click on object_1 I want object_2 and five to rotate. Could someone point me to some info on how to do this?
Thanks
****
****
****
When I click on one of the objects I want the other object that thouch it to rotate. So If I click on object_1 I want object_2 and five to rotate. Could someone point me to some info on how to do this?
Thanks
About the author
Torque Owner Scott Jaworski
function object::onMouseClick(%this) { rotateFunction(%this.value); // value is a predefined location defining number 1-16 findNeighbors(%this.value); } findNeighbors(number) { switch (number) { case 1: rotateFunction(2); rotateFunction(5); case 2: rotateFunction(1); rotateFunction(3); rotateFunction(6); case 3: rotateFunction(2); rotateFuncation(4); rotateFunction(7); etc, etc, etc case 16: rotateFunction(12); rotateFunction(15); } } rotateFunction(number){ rotate("object" @ number); //assumes your variables are called "object1" - "object16" }You might even be able to do the rotateFunction thing inline without having to write a seperate function. Not sure how the graphical rotation function works, but this method would also allow you to keep up with whatever was being changed if you wanted to keep up with anything else other than just rotating graphics. Hope that's clear and works for you as a solution. It by no means is final code; just meant to give you an idea of how to solve your problem.
Edit: I keep thinking more about it and editing it as such. The above should work for a small group, hardcoding neighbors, but you could also do it like the following if your groups are going to get larger. Save your width in a variable (a 4x4, 16 cell group, the width would be 4) and your max number in another variable and write four seperate checks for the top, left, right and bottom limits in place of the findNeighbors function above. Let's just look at it in code, shall we?
if we think about this one at a time...
top check - a value of 1-4 will yield a negative or zero value when subtracted from the width (4), so you won't rotate. Everything else from 5 - 16 will yield a positive number, so it's northern neighbor will get rotated.
bottom check - a value of 13 - 16 will yield a number higher or equal to than the max, so they won't get their lower neighbors rotated, everything else passes the check.
right check - 4, 8, 12 and 16 are equal to zero when modded by the width, 4 (4/4 = 1 with no remainder, etc) so they fail the check. everything else isn't equal to zero, so we rotate the next one up in the list (right neighbor).
left check - this one is confusing. we WANT the remainder when dividing by the width to be 1 in order to NOT rotate. 1, 5, 9 and 13 are all the left side, when you divide them by 4, you get a remainder of 1 (1/4 = 0 with a remainder of 1, etc) so those guys don't get their left neighbor rotated, everything else does (2/4 = 0 with a remainder of 2, etc).
That was probably WAY too much explanation and i've probably confused you more than you'd care to be, but that will work if your field ever gets too big to hard code neighbors in.