melonJS icon indicating copy to clipboard operation
melonJS copied to clipboard

AnimationSheet Visible Problem

Open aaschmitz opened this issue 14 years ago • 2 comments

Hi

I use an AnimationSheet with the code snipet below:

init: function(x, y) { this.parent(x, y, me.loader.getImage("IMG"), 32, 16);
this.addAnimation("default", [0, 1, 2]); this.addAnimation("special", [3, 4, 5]); this.setCurrentAnimation("default");

// Hide the object - IMPORTANT !!!
this.visible = false;

},

update: function() { // Check visibility if (this.visible) { // do something...

    this.parent();
    return true;
}

return true;

},

Then, in some other functions, I set the obj.visible = true or false. In the melonJs 0.9.4, it's all OK, but in the 0.9.5, the obj.visible = true works but ob.visible = false, not. In this case, setting the ob.visible = false, the same remains displayed in screen.

Checking the melonJs code for the two versions, I compared the code of the function api.makeDirty:

// melonJs 0.9.4 - OK // if obj is visible add it to the list of obj to draw if (obj.visible) { // add obj at index 0, so that we can keep // our inverted loop later dirtyObjects.unshift(obj); }

// melonJs 0.9.5 - Not Working // if obj is in the viewport add it to the list of obj to draw if (obj.inViewport) { // add obj at index 0, so that we can keep // our inverted loop later dirtyObjects.unshift(obj); }

Changing the code if (obj.inViewport) from 0.9.5 version to if (obj.visible) the problem was solved.

I assume that the two variables (visible and inViewport) should be used in the conditional expression? Or I'm doing something wrong?

Thanks!

aaschmitz avatar Oct 07 '12 03:10 aaschmitz

Oops, one of my patches caused this regression! The new patch fixes it. Thanks!

parasyte avatar Oct 07 '12 03:10 parasyte

Hi Jason, tested and works like a charm!

Thanks for you dedication!

aaschmitz avatar Oct 07 '12 05:10 aaschmitz