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:
But I'm only able to rotate them on the central axis, so, it forms a cross:
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.
Answer
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;
}
No comments:
Post a Comment