Jump to content

When add sprite to two groups events.onInputDown does not work?


megabyterain
 Share

Recommended Posts

Hello, everyone.

I am using Phaser 2.8.3

Basically I want to add a sprite to two groups. In my game I want three columns so I have three column groups.

this.leftColumn = game.add.group();
this.middleColumn = game.add.group();
this.rightColumn = game.add.group();

 

Later I add buttons into these groups

this.spawnRateButton = [];
this.spawnRateButton.push(this.leftColumn.create(0,0,"custom-left-button"));
this.spawnRateButton.push(this.middleColumn.create(0,0,"custom-middle-button"));
this.spawnRateButton.push(this.rightColumn.create(0,0,"custom-right-button"));
for(var i=0;i<3;i++){
    this.spawnRateButton[i].inputEnabled = true;
    this.spawnRateButton[i].events.onInputDown.add(this.buttonPress,this);
}

 

However here comes my problem. I want these columns to be scrollable, so I have to utilize this https://github.com/trueicecold/phaser-scrollable . 

this.scroller = game.add.existing(new ScrollableArea(x, y, width, height, {horizontalScroll: false})); 
//...
this.scroller.addChild(this.leftColumn);
this.scroller.addChild(this.middleColumn);
this.scroller.addChild(this.rightColumn);
this.scroller.start();

The scrolling works, however, the events.onInputDown of the spawnRateButtons do not. I click the buttons and nothing happens. When I take away the scroller everything works fine except for the scrolling, of course. When I add the sprites individually to the scroller it doesn't work either.

 

I am guessing this is because I am trying to add the sprites to two groups? Is there a correct way to do this?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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