I'm at a complete loss at how to do this:

I have my player movieclip on the stage, and when the mouse is clicked a bullet is fired and projected at the correct angle to point itself at the mouse location. I also want a "mirroring" enemy, that fires at the complete opposite direction when the player does.

For example, when the player shoots upwards, the enemy should shoot down. Likewise, shooting to the right will cause the enemy to shoot to the left.

Is there a formula to convert the rotation in degrees to it's complete opposite?

Thanks, - Ryan

有帮助吗?

解决方案

Using Matrix is a very simple and exact solution. just multiple a or c with -1 ( to flip vertical and horizontal ).

Sample code:

        var _tmpMatrix:Matrix = sprite.transform.matrix;
        _tmpMatrix.a *= -1;
        if ( _tmpMatrix.a < 0 ) {
            _tmpMatrix.tx = sprite.width + sprite.x;
        } else {
            _tmpMatrix.tx = 0;
        }
        sprite.transform.matrix = _tmpMatrix;

其他提示

Wouldn't adding or subtracting 180 degrees point in the opposite direction?

or

obj.scaleX = -1;

will do the same thing. =)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top