AS3:Sprite高速跟踪路径

时间:2012-05-28 09:30:30

标签: actionscript-3 sprite

首先抱歉一些英语错误。葡萄牙语是我的第一语言(我来自巴西)

我试图在AS3中从零开始制作太空游戏,并且移动船的方式就像在空中交通管理局的游戏中一样。

我在某些方面取得了成功。但是当船速度非常快时,它会开始摇晃,并且它不是那么平滑和干净。

以下是我所做的:http://megaswf.com/s/2437744

由于代码非常大,所以我粘贴在pastebin:pastebin.com/1YVZ23WX 我还写了一些英文文档。

这是我的第一个游戏,也是我在这里的第一篇文章。我真的希望你们能帮助我。

提前致谢。

编辑: 由于代码很大,我会在这里澄清一下。

当用户MouseDown和MouseMove船舶时,每个坐标都传递给一个数组。 当用户MouseUP将此数组传递给修复数组的函数时。

例如:如果两个坐标之间的距离大于5px,则该函数在两个坐标的中间创建一个坐标。

如果我把这个功能解决了看待解决的问题。但如果用户移动鼠标非常慢,它仍然会发生。它还会产生一个我试图用该函数解决的问题。因为当船到达一个坐标时,两个坐标的距离非常大,大部分线路消失。

我上传了一个没有修复数组功能的版本。 http://megaswf.com/s/2437775

我认为有两种方法可以解决这个问题

1-尝试修复坐标数组中的噪声2-取消在两点之间创建坐标的功能,并尝试解决线路路径问题的消失。

以下是两个重要的功能:

此功能移动船

    private function mover():void 
    {
        if (caminhoCoords[0]!=null) // caminhoCoords is the array that contain the path
        {

            var angulo:Number = Math.atan2(this.y - caminhoCoords[0][1], this.x - caminhoCoords[0][0]);
            this.rotation = angulo / (Math.PI / 180);
            this.x = this.x - velocidade * (Math.cos(angulo)); 
            this.y = this.y - velocidade * (Math.sin(angulo));

            var testex:Number = Math.abs(this.x - caminhoCoords[0][0]); //test to see the distance between the ship and the position in the array
            var testey:Number = Math.abs(this.y - caminhoCoords[0][1]);



            if (testey<=velocidade+2 && testex<=velocidade+2) // if is velocidade+2 close then go to the next coordnate
            {
                caminhoCoords.shift();
            }   
        }
    }

此功能绘制线条:

    private function desenhaCaminho():void //draw the black Path
    {
        if(caminhoCoords.length>=1) 
        {
            caminho.graphics.clear();
            caminho.graphics.lineStyle(1, 0x000000, 1,true);
            caminho.graphics.moveTo(caminhoCoords[0][0],caminhoCoords[0][1]);
            for (var i:int = 1; i < caminhoCoords.length; i++)
            {
                caminho.graphics.lineTo(caminhoCoords[i][0], caminhoCoords[i][1]);
            }
        }else 
        {
            caminho.graphics.clear();
        }
    }

每次船到达一个坐标时,都会从阵列中取出该坐标并重新绘制数组。

有更好的方法吗?

2 个答案:

答案 0 :(得分:0)

从口吃的外观来看,我猜你需要平滑一下“线”。它可能会在线路中拾取大量噪声,然后转换为平面的旋转。平滑平面的旋转/位置或线条本身。

答案 1 :(得分:0)

我相信如果您将飞机的注册点设置为中心并使用.snapto(path),则会改善操作。

相关问题