Best method to search a children id? very fast ?[SOLVED]

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
Hi
What would be the most effective way, for find a child or (sprite) in the _pictureContainer ?
PHP:
SceneManager._scene._spriteset._pictureContainer.children
The problem is that I have a lot of picture and their CHILD id are messy.!

I use the filter() method, but it is very heavy in resource, especially that can not BREAK; after the first result. !

PHP:
var pictureChild = SceneManager._scene._spriteset._pictureContainer.children.filter(function(pic) { return pic._pictureId === id; });
pictureChild.children.removeChildren(); // remove all children inside this sprite picture
Would there be? a method to quickly get the child's position ? or a way to stored Childposition in the Game Screen constructor with is INDEX ???

I would have liked, use the find () method, but it seem only ECMAScript 6 :frown:
What are your tips and advice?

and do existe something in a class , to do example
.getChildAt() ?

thank a lot for help
 
Last edited:

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
782
First Language
English
Primarily Uses
RMMV
Just loop through the children with a normal for loop and break once you have what you need.
Code:
var child;
for (var i = 0; i < children.length; i++) {
  if (children[i].someId === IDIWANT) {
    child = children[i];
    break;
  }
}
And as for the es6 functions, you can find polyfills for most of them. You can find them in external libraries or just at the mdn site. example the polyfill for Array.find can be found at the bottom of:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
Just loop through the children with a normal for loop and break once you have what you need.
Code:
var child;
for (var i = 0; i < children.length; i++) {
  if (children[i].someId === IDIWANT) {
    child = children[i];
    break;
  }
}
And as for the es6 functions, you can find polyfills for most of them. You can find them in external libraries or just at the mdn site. example the polyfill for Array.find can be found at the bottom of:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
Thank you, I did not know this term !.
i was use https://www.w3schools.com/js/ to learn & study javascript.
and not have the Polyfill !

So if I understood correctly to stay clean, I can do a js file
with all Polyfill i need
example Polyfill.js
and add im to index.html , before load my plugin.js

PHP:
<body style="background-color: black">
        <script type="text/javascript" src="js/libs/pixi.js"></script>
        <script type="text/javascript" src="js/libs/pixi-tilemap.js"></script>
        <script type="text/javascript" src="js/libs/pixi-picture.js"></script>
        <script type="text/javascript" src="js/libs/fpsmeter.js"></script>
        <script type="text/javascript" src="js/libs/lz-string.js"></script>
        <script type="text/javascript" src="js/libs/iphone-inline-video.browser.js"></script>
        <script type="text/javascript" src="js/rpg_core.js"></script>
        <script type="text/javascript" src="js/rpg_managers.js"></script>
        <script type="text/javascript" src="js/rpg_objects.js"></script>
        <script type="text/javascript" src="js/rpg_scenes.js"></script>
        <script type="text/javascript" src="js/rpg_sprites.js"></script>
        <script type="text/javascript" src="js/rpg_windows.js"></script>
<script type="text/javascript" src="js/Polyfill.js"></script>
        <script type="text/javascript" src="js/plugins.js"></script>
        <script type="text/javascript" src="js/main.js"></script>
    </body>
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
454
Reaction score
209
First Language
English
Primarily Uses
RMMV
Just a thought but if you know the id and since all ids for the children should be unique could you perhaps use Array.prototype.indexOf?
Code:
var child;
var id = children.indexOf(IDIWANT);
child = children[id];
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
Just a thought but if you know the id and since all ids for the children should be unique could you perhaps use Array.prototype.indexOf?
Code:
var child;
var id = children.indexOf(IDIWANT);
child = children[id];
In fact when we are tired we makes us stupid and incompetent.
All the pictures are well in order !!
I confused the pictureID with the spriteID !, we must admit that if we read quickly. We can confused :dizzy:
aeafdf.jpg
So calling a filter is completely stupid.
so i simply do this now and is work !

PHP:
    var pictureChild = SceneManager._scene._spriteset._pictureContainer.children[pictureId-1];
    if(pictureChild.children.length){pictureChild.removeChildren()}; // removePixiText child
 
Last edited:

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
454
Reaction score
209
First Language
English
Primarily Uses
RMMV
I know the feeling lol. There are normally a ton of ways to do something and 99% of them are overly complicated (figures out an easier way which in turn allows you to find an even simpler way). :p
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Today's patch of Eternal Dreamers is for all the gamblers out there! https://bit.ly/327mu83
i deleted anime only family guy from now on
I've discovered Stardew Valley and now I'm an addict. To think that one person designed this...
There a thread out there that tells us the best way to open an RPG that isn't 'the protag gets out of bed'?
Updated my state Stacker Script on itch.io, github is down for some reason (probs just me).

Forum statistics

Threads
94,335
Messages
920,036
Members
124,093
Latest member
JosephTucker
Top