RMMV Accessing a PIXI sprite child's index in SceneManager?

AmVa

Regular
Regular
Joined
Jul 6, 2022
Messages
105
Reaction score
30
First Language
English
Primarily Uses
RMMV
I have added a PIXI sprite to the scene using the following script call:

var mysprite = PIXI.Sprite.fromImage ("img/pictures/mysprite.png") SceneManager._scene.addChild (mysprite)

Now I'm trying to change/remove it via a separate script call (assuming the index of the added sprite is 0 or 1), but it doesn't work

I tried:
SceneManager._scene.children[0] SceneManager._scene.children[1] SceneManager._scene._spritesheet.children[1] SceneManager._scene._spritesheet._tilemap.children[1]

Clearly I'm missing something here but can't find the correct way of doing this anywhere, hopefully someone can explain
 

coyotecraft

Mythographer
Regular
Joined
Mar 13, 2012
Messages
502
Reaction score
275
First Language
English
Primarily Uses
N/A
It's index is going to be last. SceneManager._scene already has 2 children, the spriteset map and window layer. So you might try SceneManager._scene.children[2]
However, I can't account for any plugins might have created their own children. Like cosmetic lighting or shadow plugins. So it could be anything.

You can inspect SceneManager._scene.children with something like
console.log(SceneManager._scene.children)

open the debug console during playtesting with f12.
 

AmVa

Regular
Regular
Joined
Jul 6, 2022
Messages
105
Reaction score
30
First Language
English
Primarily Uses
RMMV
Thank you! that was indeed the problem

However I noticed that once I open the menu scene and go back to the map scene, the sprite I added is gone. Is there another line that is needed in order to maintain it on the screen before/after "SceneManager._scene.addChild"?
 

Trihan

Speedy Scripter
Regular
Joined
Apr 12, 2012
Messages
6,551
Reaction score
7,103
First Language
English
Primarily Uses
RMMZ
Thank you! that was indeed the problem

However I noticed that once I open the menu scene and go back to the map scene, the sprite I added is gone. Is there another line that is needed in order to maintain it on the screen before/after "SceneManager._scene.addChild"?
This is because when you transition between the menu and the map, it actually reloads the map scene, thus any changes you made in code before entering the menu will no longer be there because it's a "fresh" map. You could programmatically rewrite Scene_Map's initialize function to add the child there, that would make it stop disappearing. But it would also only last for the current game session, and would persist if you loaded a save where the sprite wasn't meant to be there. Outside of plugins, there are few ideal solutions to this problem.
 

AmVa

Regular
Regular
Joined
Jul 6, 2022
Messages
105
Reaction score
30
First Language
English
Primarily Uses
RMMV
Thanks!
You could programmatically rewrite Scene_Map's initialize function to add the child there, that would make it stop disappearing. But it would also only last for the current game session, and would persist if you loaded a save where the sprite wasn't meant to be there.
the sprite is part of the HUD so it needs to be loaded whenever the map scene is loaded...
since I have a parallel event that constantly changes it, I thought of maybe adding the child within that same event, under a conditional branch that checks if the map scene was loaded?

I'm planning on creating my own menu scene anyway and disable the default one, so not sure if that's going to be an issue later
 

Latest Threads

Latest Profile Posts

Why is it always "people meant to be in your life, will be"? Why don't those people realize it works in reverse? If you were meant to be in THEIR LIVES, you would be?
Wow, it's almost a month since the last time I made a full-scale drawing. But I'm back to the drawing board again.
F7L1ME2aMAAo4jK
Well, I think it’s a competent enough sketch. Definitely a lot of smaller details that will get inked and the hands and feet naturally need a ton of revision (legs might be a little long too). Yes. I will also draw the second hand…I just think I’ve suffered enough, OK?

IMG_0488.jpeg
wahh, it's good to be back! A lot of stuff happened (like always lmao) but I've been extremely productive lately, so I decided to hop on back onto the forum I definitely have warm feelings to! haroo eberyoneee :kaohi:

Forum statistics

Threads
134,894
Messages
1,251,693
Members
177,708
Latest member
lukanwhitehouse
Top