Jump to content

how to loop in this and detect object


espace
 Share

Recommended Posts

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

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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...