Actionscript 3 在actionscript 3中,在另一个电影剪辑与其相交的点处将线弯曲90度

Actionscript 3 在actionscript 3中,在另一个电影剪辑与其相交的点处将线弯曲90度,actionscript-3,movieclip,flash-cs6,Actionscript 3,Movieclip,Flash Cs6,基本上,我正在用Flash CS6制作一个游戏,其中一个光源投射到屏幕上。你有一面镜子,你可以把它拖来拖去。然而,当镜子接触到光线时,它会反弹,并在撞到镜子后偏移90度 我没有足够的声誉来发布图片,但这里有一个链接可以解释这个问题: 如果你能帮我解决这个问题,我会非常高兴。 提前感谢,, -Raph这是一个非常快速和肮脏的例子,让球滚动。这段代码有很多问题,所以我建议您仅将其用作起点。详细信息在代码中注释 package { import flash.display.Sprite;

基本上,我正在用Flash CS6制作一个游戏,其中一个光源投射到屏幕上。你有一面镜子,你可以把它拖来拖去。然而,当镜子接触到光线时,它会反弹,并在撞到镜子后偏移90度
我没有足够的声誉来发布图片,但这里有一个链接可以解释这个问题:
如果你能帮我解决这个问题,我会非常高兴。

提前感谢,,
-Raph

这是一个非常快速和肮脏的例子,让球滚动。这段代码有很多问题,所以我建议您仅将其用作起点。详细信息在代码中注释

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class MirrorTest extends Sprite 
    {

        private var _mirror:Sprite;
        private var _line:Sprite;

        public function MirrorTest() 
        {
            super();

            // create the line clip
            _line = addChild(new Sprite()) as Sprite;
            _line.graphics.clear();
            _line.graphics.lineStyle(3, 0xFF0000);
            _line.graphics.moveTo(0, 0);
            _line.graphics.lineTo(500, 0); // starting it off at an arbitrary width
            _line.y = 100; // positioning line so that we can see when it bends upwards

            // create the mirror clip
            _mirror = addChild(new Sprite()) as Sprite;

            // draw a square and rotate it so we have a diamond shape
            _mirror.graphics.beginFill(0);
            _mirror.graphics.drawRect(-20, -20, 40, 40);
            _mirror.graphics.endFill();
            _mirror.rotation = 45;
            _mirror.x = _mirror.y = 200; // position the mirror away from the line

            // add even listeners to trigger dragging/dropping
            _mirror.addEventListener(MouseEvent.MOUSE_DOWN, dragMirror);
            _mirror.addEventListener(MouseEvent.MOUSE_UP, dropMirror);

        }

        private function dragMirror($event:MouseEvent):void 
        {
            // start dragging the mirror. 
            _mirror.startDrag(true);
            // add the ENTER_FRAME listener so that we can check for colision as the mirror is being moved around
            addEventListener(Event.ENTER_FRAME, onTick);
        }

        private function dropMirror($event:MouseEvent):void 
        {
            // stop dragging the mirror
            _mirror.stopDrag();
            // remove the ENTER_FRAME listener so we don't waste cycles checking for collision when the mirror is not being moved around
            removeEventListener(Event.ENTER_FRAME, onTick);
        }

        private function onTick($event:Event):void 
        {
            // check to see if the mirror has collided with the line
            if (_mirror.hitTestObject(_line))
            {
                // if so, redraw the line as a right-angle, using the mirror's position as the "collision point"
                _line.graphics.clear();
                _line.graphics.lineStyle(3, 0xFF0000);
                _line.graphics.moveTo(0, 0);
                _line.graphics.lineTo(_mirror.x - _mirror.width * .5, 0);
                _line.graphics.lineTo(_mirror.x - _mirror.width * .5, -100);
            }
            else
            {
                // if not, redraw the original line
                _line.graphics.clear();
                _line.graphics.lineStyle(3, 0xFF0000);
                _line.graphics.moveTo(0, 0);
                _line.graphics.lineTo(500, 0);
            }

        }

    }

}

镜子总是在45度到激光吗?在这一点上发展,它将是,但未来的水平可以包括不同角度镜子-简短的回答是的。我意识到我的问题不是很好,所以我重新张贴它-在未来,请考虑编辑您当前的问题,而不是张贴一个新的(重复)问题。对不起!!!!!!!我以后肯定会编辑问题。谢谢你的快速回复-我现在正在测试你的代码。这会在第14行抛出一个错误,说:1007:super语句只能在类实例构造函数中使用。我不明白这个错误。我猜您没有将文件命名为
MirrorTest.as
。无论哪种方式,都可以在构造函数中删除对
super()
的调用,它应该可以正常工作。