Sign in to follow this  
megabyterain

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

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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.