문제

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