I’m creating a maze-like thing. It’s a 4x4 grid and each room has a button in it which behaves differently. Well, I have 5 different rooms that are just placed about the grid - the room itself is a button. For example - clicking on one type of room button rotates that room 90 degrees. That was easy to code.
I’m currently stuck on a button which I want to rotate a 2x2 portion of the grid about the point in the middle. The room it goes in is an L, and the ones affected would make up a square as if that was the bottom-left corner. Of course, if I rotated the L so it was an ¬ then it’s the top-right corner of the 2x2.
At the moment I have a hittest to determine which rooms will be affected. And I can even get all the rooms affected to do their little animation.
I then went on to pasted in the code I previously used to rotate a single room about itself and, as suspected, they’re all just rotating about themselves.
Here’s my code at the moment, and I’ve only included the rotations for those first affected. Obviously there’d be a lot more hit-tests including the whole grid.
two.onRelease = function() {
if (hitspot.hitTest(_root.mapc)==true)
{
if (_root.mapc._currentframe < 9) {
gotoAndStop(10);
_root.mapc._rotation += 90;
play();
}
else {
_root.mapc._rotation += 90;
play();
}
}
if (hitspot.hitTest(_root.mapd)==true)
{
if (_root.mapd._currentframe < 9) {
gotoAndStop(10);
_root.mapd._rotation += 90;
play();
}
else {
_root.mapd._rotation += 90;
play();
}
}
if (hitspot.hitTest(_root.maph)==true)
{
if (_root.maph._currentframe < 9) {
gotoAndStop(10);
_root.maph._rotation += 90;
play();
}
else {
_root.maph._rotation += 90;
play();
}
}
if (_root.mapg._currentframe < 9) {
gotoAndStop(10);
_root.mapg._rotation += 90;
play();
}
else {
_root.mapg._rotation += 90;
play();
}
}
I’ve created an invisible dot that lies in the centre of the hitzone called “centre” and as that room and the hitspot all rotate themselves the centre will always lie where I want the centre to be - so I don’t need any midpoint calculations.
_root.map#._rotation += 90;
^
How do I make that rotate 90 degrees about a specified point, not just it’s own middle.