laya---直线移动

Posted 格拉格拉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laya---直线移动相关的知识,希望对你有一定的参考价值。

beginMove(result: Function) 
        let width;
        let height;
        let ratio;
        let isXmax;

        if (this.ownFwy_cp.x > 0 && this.moveTaget.x > 0) 
            if (this.ownFwy_cp.x > this.moveTaget.x) 
                width = this.ownFwy_cp.x - this.moveTaget.x;
             else 
                width = this.moveTaget.x - this.ownFwy_cp.x;
            
         else if ((this.ownFwy_cp.x > 0 && this.moveTaget.x < 0) || (this.ownFwy_cp.x < 0 && this.moveTaget.x > 0)) 
            width = Math.abs(this.ownFwy_cp.x) + Math.abs(this.moveTaget.x);
        
        else 
            if (Math.abs(this.ownFwy_cp.x) > Math.abs(this.moveTaget.x)) 
                width = Math.abs(this.ownFwy_cp.x) - Math.abs(this.moveTaget.x);
             else 
                width = Math.abs(this.moveTaget.x) + Math.abs(this.ownFwy_cp.x);
            
        

        if (this.ownFwy_cp.y > 0 && this.moveTaget.y > 0) 
            if (this.ownFwy_cp.y > this.moveTaget.y) 
                height = this.ownFwy_cp.y - this.moveTaget.y;
             else 
                height = this.moveTaget.y - this.ownFwy_cp.y;
            
         else if ((this.ownFwy_cp.y > 0 && this.moveTaget.y < 0) || (this.ownFwy_cp.y < 0 && this.moveTaget.y > 0)) 
            height = Math.abs(this.ownFwy_cp.y) + Math.abs(this.moveTaget.y);
        
        else 
            if (Math.abs(this.ownFwy_cp.y) > Math.abs(this.moveTaget.y)) 
                height = Math.abs(this.ownFwy_cp.y) - Math.abs(this.moveTaget.y);
             else 
                height = Math.abs(this.moveTaget.y) + Math.abs(this.ownFwy_cp.y);
            
        

        if (width > height) 
            ratio = width / height;
            isXmax = true;
         else 
            ratio = height / width;
            isXmax = false;
        
        console.log("w:" + width + "...h:" + height + "...r:" + ratio);

        Laya.timer.frameLoop(1, this, () => 
            
            if(isXmax)
                if (this.ownFwy_cp.x > this.moveTaget.x) 
                    this.ownFwy_cp.x -= this.moveSpeed;
                    if (this.ownFwy_cp.x <= this.moveTaget.x) 
                        this.ownFwy_cp.x = this.moveTaget.x;
                    
                 else if (this.ownFwy_cp.x < this.moveTaget.x) 
                    this.ownFwy_cp.x += this.moveSpeed;
                    if (this.ownFwy_cp.x > this.moveTaget.x) 
                        this.ownFwy_cp.x = this.moveTaget.x;
                    
                
                if (this.ownFwy_cp.y > this.moveTaget.y) 
                    this.ownFwy_cp.y -= this.moveSpeed/ratio;
                    if (this.ownFwy_cp.y < this.moveTaget.y) 
                        this.ownFwy_cp.y = this.moveTaget.y;
                    
                 else if (this.ownFwy_cp.y < this.moveTaget.y) 
                    this.ownFwy_cp.y += this.moveSpeed/ratio;
                    if (this.ownFwy_cp.y > this.moveTaget.y) 
                        this.ownFwy_cp.y = this.moveTaget.y;
                    
                
            else
                if (this.ownFwy_cp.x > this.moveTaget.x) 
                    this.ownFwy_cp.x -= this.moveSpeed/ratio;
                    if (this.ownFwy_cp.x <= this.moveTaget.x) 
                        this.ownFwy_cp.x = this.moveTaget.x;
                    
                 else if (this.ownFwy_cp.x < this.moveTaget.x) 
                    this.ownFwy_cp.x += this.moveSpeed/ratio;
                    if (this.ownFwy_cp.x > this.moveTaget.x) 
                        this.ownFwy_cp.x = this.moveTaget.x;
                    
                
                if (this.ownFwy_cp.y > this.moveTaget.y) 
                    this.ownFwy_cp.y -= this.moveSpeed;
                    if (this.ownFwy_cp.y < this.moveTaget.y) 
                        this.ownFwy_cp.y = this.moveTaget.y;
                    
                 else if (this.ownFwy_cp.y < this.moveTaget.y) 
                    this.ownFwy_cp.y += this.moveSpeed;
                    if (this.ownFwy_cp.y > this.moveTaget.y) 
                        this.ownFwy_cp.y = this.moveTaget.y;
                    
                
            

            if (this.ownFwy_cp.x == this.moveTaget.x && this.ownFwy_cp.y == this.moveTaget.y) 
                Laya.timer.clearAll(this);
                result(true);
            
        );
    

以上是关于laya---直线移动的主要内容,如果未能解决你的问题,请参考以下文章

直线移动汽车

Laya资源加载小记

Laya中使用Navmesh寻路

Laya自动图集原理

laya怎么把as3swf转化成二进制

laya3d启动失败