PLAYERKILLERS Posted January 31, 2019 Share Posted January 31, 2019 https://melonjs.github.io/melonJS/docs/me.Renderable.html#onVisibilityChange this.onVisibilityChange = function(inViewport) { if (inViewport === true) { console.log("object has entered the in a camera viewport!"); } }; The suggested code doesn't work at all for me. inViewport could be either 1, 0, or false. melon.js line 9165 Object.defineProperty(me.Renderable.prototype, "inViewport", { /** * @ignore */ get : function () { return this._inViewport; }, /** * @ignore */ set : function (value) { if (this._inViewport !== value) { this._inViewport = value; if (typeof this.onVisibilityChange === "function") { this.onVisibilityChange.call(this, value); } } }, configurable : true }); Even after editing this to: if (this._inViewport != value) { The event still fires frequently while an enemy sprite is on screen. Quote Link to comment Share on other sites More sharing options...
obiot Posted January 31, 2019 Share Posted January 31, 2019 hi, I'm not sure I understand what you mean; are u saying that inViewport is sometimes equal to 1 or 0 ? in theory this should not be possible, as the value is the one returned by the camera isVisible function, that always returns true or false : https://github.com/melonjs/melonJS/blob/master/src/renderable/container.js#L836 https://github.com/melonjs/melonJS/blob/master/src/camera/camera2d.js#L575 Quote Link to comment Share on other sites More sharing options...
PLAYERKILLERS Posted February 1, 2019 Author Share Posted February 1, 2019 Yes, it is either 1, 0, or false in my testing. The event fires even when the the NPC is in the viewport. When the NPC has actually exited the screen it will be 0. The camera code seems to be setting 0 or 1. The default is false. Quote Link to comment Share on other sites More sharing options...
obiot Posted February 1, 2019 Share Posted February 1, 2019 really ??? ok, I'll investigate this one further to see where this 1 or 0 is coming, thanks ! Quote Link to comment Share on other sites More sharing options...
obiot Posted February 1, 2019 Share Posted February 1, 2019 so yeah, not sure why to be honest, maybe the combination of bitwise operation and using getter, but indeed sometimes a non Boolean value was passed ! the fix is quite easy actually, have a look below in case you want to fix it in your current build without/while waiting for the 6.4.0 version (I will release it within a few days): https://github.com/melonjs/melonJS/commit/117d083b70d82bcacb35767c24d1c1aaba26579b thank you for the feedback ! PLAYERKILLERS 1 Quote Link to comment Share on other sites More sharing options...
PLAYERKILLERS Posted February 1, 2019 Author Share Posted February 1, 2019 It is just another one of those js type issues. Perplexes me as well. Thank you for the game library and support. obiot 1 Quote Link to comment Share on other sites More sharing options...
obiot Posted February 2, 2019 Share Posted February 2, 2019 found and fixed a similar case https://github.com/melonjs/melonJS/commit/43d91c800fa684ae2fe61e26d183842cc254dfcb PLAYERKILLERS 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.