codeing or artist ?
记得大学第一节编程课,教授说,"如果一件事儿有对错,那么是科学。如果有美丑好坏,那么是艺术。" 一个能顺利运行还能让人阅读时体验思维美妙的代码,就是艺术和科学的结合。能运行的程序并不是好程序,能当作文章来读的才是。在我看来代码是一种特殊的文体,程序猿其实会写诗。

不啰嗦上代码:

//判断鼠标当前坐标是否在当前渲染对象区域中
        isMouseIn:function(){
            var x = Mouse.gX() || Touch.gX(),
                y = Mouse.gY() || Touch.gY();
            var sc = this.owner;var gx = sc.x,
                gy = sc.y;
            //转换鼠标坐标到游戏窗口坐标系
            var cd = xengine.fn.MathUtil.mapSToCoord(x,y,gx,gy);
            var hw  = this.w*0.5,
                hh = this.h*0.5;
            return cd[0] >= this.x-hw && cd[0] <= this.x + hw && cd[1] >= this.y - hh && cd[1] <= this.y + hh;
        }
//以屏幕上左上角为原点,x1,y1为坐标的点转向以ox,oy为原点的坐标
            mapSToCoord:function(x1,y1,ox,oy){
                return [x1-ox,y1-oy];
            },

 

posted on 2016-08-29 17:08  codeing-or-artist-??  阅读(250)  评论(0编辑  收藏  举报