Disposing a Sprite in MV (what's the correct method)

I realised now that RPG Maker MV doesn't have dispose methods. What's the cleanest way to dispose a sprite in RPG Maker MV, for good practice plugin creation? 🙂 )

does: 

this._mysprite.bitmap = null;this._mysprite = null;do the trick? do I need both or only the second one? 😀

Thank you for your time.

EDIT: I found a post on this!! So... I think I got my answer.. thought if I can I would like to ask something else, how do I know if the contents of a given window is bigger than the window size?! On older RPG Makers the contents.bitmap ... would be the size of all the contents and would use a viewport and offset to show only part of it... right now... I've been looking at the code and I think MV handles it differently. that being how can I know if it contents height are bigger that the window?
Can you please post the answer you found, or at least a link to the post? This way if someone comes here in the future, this post may help them get their answer.

As for your other question, you can still use the contentsWidth() and contentsHeight() functions that were also available in Ace.
Can you please post the answer you found, or at least a link to the post? This way if someone comes here in the future, this post may help them get their answer.

As for your other question, you can still use the contentsWidth() and contentsHeight() functions that were also available in Ace.
Thank you for the quick answer 🙂

The link is actually a post here: http://forums.rpgmakerweb.com/index.php?/topic/50479-dispose-in-js-is-removechild/

so

if this.contentsHeight() > this.windowHeight(); 

the window is scrollable?! doesn't seem to work 🙁
Ahh, you meant the size of what you want to draw, not the size of the drawable area. Well, that's not really possible in MV. The contents bitmap is made to be exactly the size of the display area, so there is not hidden content by default in any windows. Even in selectable windows like the command windows, there is no content actually drawn outside of the bitmap, everything is drawn in as it's needed. So, in order for you to see if your content is bigger than the size of the window, you'll need a way to measure your content itself.

Sorry that doesn't really help, but there's no way to draw outside of a window's display area by default, as the bitmap is limited to that size.
If that's the case, wouldn't you be able to change the createContents() so the contents.bitmap uses the full page size? Then wouldn't you be able to draw on parts off the window. And when scrolling just change the contents bitmaps offset? I did something similar to this in VXA which worked, so pretty sure it would work here.
Ahh, you meant the size of what you want to draw, not the size of the drawable area. Well, that's not really possible in MV. The contents bitmap is made to be exactly the size of the display area, so there is not hidden content by default in any windows. Even in selectable windows like the command windows, there is no content actually drawn outside of the bitmap, everything is drawn in as it's needed. So, in order for you to see if your content is bigger than the size of the window, you'll need a way to measure your content itself.

Sorry that doesn't really help, but there's no way to draw outside of a window's display area by default, as the bitmap is limited to that size.
I don't want to draw outside the window!! I just want to know if the contents are bigger than the window it self... I tried

itemHeight() * Math.ciel(maxItems()/maxCols()); but for some reason it sometimes doesn't work for example it doesn't work in items menu....

PS: I'm using Yanfly item core can it be the reason?!
It is possible to (partly) implement the way viewports worked in Ace when using PIXI.RenderTexture, but it has a lot of drawbacks, namely:

- x/y position of everything drawn to the texture is reset to 0/0.

- rotation is reset.

- opacity is reset (though paintOpacity still works).

The former 2 can be solved by wrapping everything inside a subclass of PIXI.DisplayObjectContainer (like Sprite) and render this. The latter can be resolved by setting the opacity on the sprite containing the renderTexture before each render.

For my minimap (work in progress), i'm doing it like this:

(function($) {    ($.prototype = Object.create(PIXI.DisplayObjectContainer.prototype)).constructor = $;    $.prototype.initialize = function() {        PIXI.DisplayObjectContainer.call(this);        this.x = _params.frame.x;        this.y = _params.frame.y;        this._minimapSprite = new IAVRA.MINIMAP.SpriteContainer();        this._renderSprite = new PIXI.Sprite(new PIXI.RenderTexture(_params.frame.w, _params.frame.h));        this.addChild(this._renderSprite);    };    $.prototype.update = function() {        this._minimapSprite.update();        this._renderSprite.texture.render(this._minimapSprite, null, true);    };    })(IAVRA.MINIMAP.RenderContainer);This will render everything inside _minimapSprite inside the rect (_params.frame.x, _params.frame.y, _params.frame.w, _params.frame.h), cutting off everything outside of it. Of course this means you are effectively drawing everything twice (first to the texture, the to the screen), but the second render is much faster, since all your sprites have been merged to a single texture.

Note that _minimapSprite isn't added as child, otherwise it would be displayed twice.

Another solution would be to call setFrame() on the sprite you want to restrict, although this needs to be done for every children of a given container and if your are dealing with fractional numbers you might get stuttering at the borders.
I don't want to draw outside the window!! I just want to know if the contents are bigger than the window it self... I tried

itemHeight() * Math.ciel(maxItems()/maxCols()); but for some reason it sometimes doesn't work for example it doesn't work in items menu....

PS: I'm using Yanfly item core can it be the reason?!
How doesn't it work? Does it crash with an error message? If so, what does it say?
I believe its removeChild
How doesn't it work? Does it crash with an error message? If so, what does it say?
my bad I was using this.height... instead of this.contentsHeight() which already takes off the padding xD everything is okay now 😀

I realised that

removeChild(this._sprite)this._sprite = null; handles disposing well. I was having troubles setting sprite.bitmap to null and sprite to null skipping removeChild... and now I'm using it and it works very good 😀 thank you for the answers!!
You don't really need to do this._sprite =null
Only if the container is terminated afterwards (in which case you don't even need the removeChild()). The sprite is originally referenced twice: In "children" array and directly as "this._sprite". As long as the sourrounding container is reachable from the root and one of these references exists, the sprite won't be cleaned by the garbage collector.


On a sidenote: If you don't need to interact with the child, it's unnecessary to add it as an attribut in the first place.

Original thread: https://forums.rpgmakerweb.com/threads/disposing-a-sprite-in-mv-whats-the-correct-method.51536/