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

xDGameStudios

Veteran
Veteran
Joined
Sep 15, 2012
Messages
102
Reaction score
60
First Language
Portuguese
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? :D

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?
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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.
 

xDGameStudios

Veteran
Veteran
Joined
Sep 15, 2012
Messages
102
Reaction score
60
First Language
Portuguese
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 :(
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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.
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
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.
 

xDGameStudios

Veteran
Veteran
Joined
Sep 15, 2012
Messages
102
Reaction score
60
First Language
Portuguese
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?!
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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.
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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?
 

xDGameStudios

Veteran
Veteran
Joined
Sep 15, 2012
Messages
102
Reaction score
60
First Language
Portuguese
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 :D

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 :D thank you for the answers!!
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
You don't really need to do this._sprite =null
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top