cocos2d / cocos2d-html5

Cocos2d for Web Browsers. Built using JavaScript.
https://www.cocos.com
3.06k stars 903 forks source link

Fix variable check for non-null & clean up #3559

Open PimsJay01 opened 6 years ago

PimsJay01 commented 6 years ago

I use function getTileAt of TMXLayer who accept as parameter a cc.Point or 2 integers. I found a bug present in almost every getters of class TMXLayer. If two integers are passed to function and x is equal to 0, function throw error "cc.TMXLayer.getTileAt(): pos should be non-null". Indeed, function to filter value was :

getTileAt: function (pos, y) {
    if (!pos) {
        throw new Error("cc.TMXLayer.getTileAt(): pos should be non-null");
    }
    ...
}

this check return true if :

I suppose that only null or undefined values have to throw error. So I suggest to change check as if(pos == null)

I also took the liberty to change every if(pos === undefined) by if(pos == null) to filter undefined and null values.

Is there any test for this class ?