Making objects in group non-interactive

I’m trying to migrate a project from P2 to P3.
I populate a row and make the objects (obj) in the row and add them to a group.
But later I want to set the whole row non-interactive, I can’t seem to access them any way without throwing an error.
in create:
//row8
this.positions =[{x: 55, y:440}, {x:110, y:440}, {x:165, y:440}, {x:220, y:440}];
this.group8 = this.add.group();
for(var i in this.positions){
//create the sprite
this.pos = this.positions[i];
this.obj = this.add.sprite(this.pos.x, this.pos.y, ‘colours’, 6).setInteractive();
//on click call the clicked function
this.obj.on(‘pointerdown’, this.clicked);
//add the sprite to the group for the row
this.group8.add(this.obj);
}
//enter button
this.enter8 = this.add.image(280, 440, ‘enter’).setInteractive();
this.enter8.on(‘pointerdown’, this.onEnter8);
};

gameScene.onEnter8 = function(){
//this is the line that I don’t understand/can’t get to work.
this.group8.getChildren.setInteractive(false);
}

Two issues with the line you’re having trouble with.

First, getChildren is a function, so you need to call it rather than just access it. So for that, you’d say this.group8.getChildren() instead of this.group8.getChildren.

Second, getChildren returns an array, so you’ll need to iterate over all the game objects in it and call setInteractive(false) on each of them. Phaser provides a nice way to do this with the Phaser.Actions.Call method. So it could look something like this:

Phaser.Actions.Call(this.group8.getChildren(), function(child) {
  child.setInteractive(false);
});

Many thanks!
Unfortunately, while it doesn’t throw an error, it doesn’t work: the interactivity here is the sprite frame changing on click. I want to stop that ability with this setInteractive(false). Is this not how to turn off that ability?

In other words, I want to make them un-clickable.

sorry for the noob question. Finding P3 more difficult than P2.

Ah, no its not. You want to use disableInteractive().

3 Likes

Hallelujah! Been stuck on that for hours! :relieved: