判断鼠标当前坐标是否在当前渲染对象区域中

不啰嗦上代码:

//判断鼠标当前坐标是否在当前渲染对象区域中
        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];
            },
原文地址:https://www.cnblogs.com/gongshunkai/p/5818743.html