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

AmVa

Veteran
Veteran
Joined
Jul 6, 2022
Messages
92
Reaction score
21
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
Veteran
Joined
Mar 13, 2012
Messages
470
Reaction score
265
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

Veteran
Veteran
Joined
Jul 6, 2022
Messages
92
Reaction score
21
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
Veteran
Joined
Apr 12, 2012
Messages
6,149
Reaction score
6,296
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

Veteran
Veteran
Joined
Jul 6, 2022
Messages
92
Reaction score
21
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 Posts

Latest Profile Posts



Chapters advancing demonstration.
Main character roey will be revived after chapter 7, so the animations will be different after it
The title of the main characters will be ascended to celestial as well as wings and rings.
Next Up. The 2nd floor of the Western Academy!

Base:
Map012.png

With a little parallax magic *:



WestAcademyFl2.png


Anything you'd add?
BUwvmx.png


Introducing a new and exciting challenge mode!! Is our demo too easy? Did you get a rare pull and want to show off on stream? Please talk to the mysterious 2nd announcer who has 6 additional challenges PER ROUND! As a game developer, I struggled to complete some of the stage 2 challenges, so I hope you tactics fans have a blast!
AeroPergold wrote on Woratana's profile.
You gucci, Woratana?
so wild I came across a video about side-scrollers for RPG Maker and my game was used as an example in the video. I really felt honored to be honest.

Forum statistics

Threads
131,639
Messages
1,221,823
Members
173,385
Latest member
VoidKass1
Top