Jump to content

me.Renderable.onVisibilityChange()


PLAYERKILLERS
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...