0
\$\begingroup\$

In my game, I have made 4 lines with different colors to form a square but the colored lines are different objects. I want to rotate the lines in a way that the lines will still form a square. Eg: enter image description here

But I'm only able to rotate them on the central axis, so, it forms a cross: enter image description here

The code for leftPressed is:

if(leftPressed)
{
black.rotation -= 90;
blue.rotation -= 90;
yellow.rotation -= 90;
red.rotation -= 90;
}

So, I need to know how to rotate objects on different axes.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

addChild() each line into a new parent DisplayObject called square. Then rotate square instead of each of the children, individually. Flash will handle the correct rotation of the children therein.

Do this once:

var square:DisplayObject = new Sprite(); //Can't instantiate DisplayObject - it's abstract. So use Sprite.

//you'll need to get references to each of the lines used here (left to you):
square.addChild(black);
square.addChild(blue);
square.addChild(yellow);
square.addChild(red);

Do this every update:

if (leftPressed)
{
    square.rotation -= 90;
}
\$\endgroup\$
7
  • \$\begingroup\$ Can you give an example or anything?? \$\endgroup\$ Commented Jun 30, 2017 at 15:25
  • \$\begingroup\$ @uvrichest Example added. \$\endgroup\$
    – Engineer
    Commented Jun 30, 2017 at 15:29
  • \$\begingroup\$ I did the exact same thing but my character is now dying automatically as it enters the scene \$\endgroup\$ Commented Jun 30, 2017 at 16:13
  • \$\begingroup\$ @uvrichest Well, I've answered your question as it was put. You need to figure out how to make it work with your own code. Ask another, separate question and mark this as accepted. (checkmark beside answer) \$\endgroup\$
    – Engineer
    Commented Jun 30, 2017 at 16:14
  • \$\begingroup\$ After adding other objects as child of the main one, the objects seem to rotate by making the object an axis. \$\endgroup\$ Commented Jun 30, 2017 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .