Marine Posted September 20, 2018 Share Posted September 20, 2018 I gave the names to my Containers and want to get them using that names(with setName ). For example, I have Container with name 'Container1', 'Container2' ... I want to find the container with 'Container2' name. How can I do that? Link to comment Share on other sites More sharing options...
iKest Posted September 20, 2018 Share Posted September 20, 2018 get from? Link to comment Share on other sites More sharing options...
Marine Posted September 20, 2018 Author Share Posted September 20, 2018 1 hour ago, iKest said: get from? Get them using names that i gave Link to comment Share on other sites More sharing options...
iKest Posted September 20, 2018 Share Posted September 20, 2018 get from scene, group, array, object etc? Link to comment Share on other sites More sharing options...
samme Posted September 20, 2018 Share Posted September 20, 2018 Phaser doesn't track Game Objects by name, but it's pretty easy to do. Remember to empty the list when leaving the scene. var containers = {}; containers[container1.name] = container1; // etc. Link to comment Share on other sites More sharing options...
iKest Posted September 20, 2018 Share Posted September 20, 2018 Phaser does track Game Objects by name with getByName(...) or getAll('name', ...) methods Link to comment Share on other sites More sharing options...
samme Posted September 20, 2018 Share Posted September 20, 2018 Well, it doesn't track them, but it can search them. Phaser.Actions.GetFirst(containers, { name: 'Container1' }); Link to comment Share on other sites More sharing options...
Marine Posted September 21, 2018 Author Share Posted September 21, 2018 9 hours ago, iKest said: Phaser does track Game Objects by name with getByName(...) or getAll('name', ...) methods I'm getting null when typing this.container.getByName('3') . inside my containers there is an image and this -> this.container.getByName() return my Image which does not have name. I think thats because i gave null. But i want to return not the Image but Container Link to comment Share on other sites More sharing options...
Marine Posted September 21, 2018 Author Share Posted September 21, 2018 8 hours ago, samme said: Well, it doesn't track them, but it can search them. Phaser.Actions.GetFirst(containers, { name: 'Container1' }); Im getting error this way too. My code is -> Phaser.Actions.GetFirst(this.squareContainer, { name: '1' }) Link to comment Share on other sites More sharing options...
iKest Posted September 21, 2018 Share Posted September 21, 2018 10 hours ago, samme said: Well, it doesn't track them, but it can search them. Phaser.Actions.GetFirst(containers, { name: 'Container1' }); We tо pour water into a sieve. Link to comment Share on other sites More sharing options...
eddieone Posted November 26, 2018 Share Posted November 26, 2018 If you use es6, you can use for of. Or for loop with es5 searchContainer(container, name) { for (var child of container.list) { if (child.name == name) { return child; } } } Link to comment Share on other sites More sharing options...
Recommended Posts