espace Posted January 9, 2017 Share Posted January 9, 2017 hi, i'm searching to loop in my this.prototype and for each object allow or not a draggable behavior.Cancel like this, i can organize my game with a simple function that reproduce a pseudo editor. see my snippet, especialy my function MonsterGroup.prototype.foreach_allow_or_not_drag=function(this_something){ is it possible ? var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:preload, create: create }); function preload() { game.load.image('circle', 'https://s13.postimg.org/xjhlzmiev/disc_png.png'); game.load.image('rect', 'http://s10.postimg.org/6fa6mgrd5/motif.jpg'); } //E for external module var sprite={} var circle={} MonsterGroup = function (game, image,image2) { Phaser.Group.call(this, game); for (var i = 0; i < 10; i++) { sprite[i] = this.create(100+i, game.world.randomY, image); sprite[i].scale.setTo(.2,.2) } this.button=game.add.sprite(100,100,'circle') this.flag=true //return sprite }; MonsterGroup.prototype = Object.create(Phaser.Group.prototype); MonsterGroup.prototype.constructor = MonsterGroup; //HERE IS WHAT IM LOOKING FOR MonsterGroup.prototype.foreach_allow_or_not_drag=function(this_something){ if (this.flag){ //for all object included array in my prototype > detect object and no_object like flag this_something.inputEnabled = true; this_something.input.enableDrag(true); } } function create() { customGroup1 = new MonsterGroup(game, 'rect','circle'); customGroup1.alpha=1 sprite[1].alpha =.2 } https://jsfiddle.net/espace3d/6tbb041u/ in fact i must detect object and not object like flag or something else. thanks for you reply. Link to comment Share on other sites More sharing options...
espace Posted January 10, 2017 Author Share Posted January 10, 2017 anybody for this ? Link to comment Share on other sites More sharing options...
drhayes Posted January 10, 2017 Share Posted January 10, 2017 Check out Object.keys. It'll return an array of the own enumerable properties on the object (so, nothing coming in from its prototype chain). You could then call "forEach" on that array and do stuff. You could also write a for..in loop, which *will* bring in stuff from the prototype chain if it matters. espace 1 Link to comment Share on other sites More sharing options...
espace Posted January 10, 2017 Author Share Posted January 10, 2017 okay https://jsfiddle.net/espace3d/ncyf9c28/ but how do you access a special value like object.x with this function ? sorry but i'm a little bit loss. Link to comment Share on other sites More sharing options...
espace Posted January 10, 2017 Author Share Posted January 10, 2017 it's done thanks for your tip https://jsfiddle.net/cz3pr4u4/ Link to comment Share on other sites More sharing options...
Recommended Posts