mattcolman / phaser-list-view

List view class for Phaser. Great for high scoreboards.
http://mattcolman.com/labs/phaser-list-view/index.html
MIT License
115 stars 21 forks source link

Click Events doesn't work on elements inside list #14

Closed QuipHop closed 7 years ago

QuipHop commented 7 years ago

Hi I'm trying to add click event on the item inside list and this event won't fire my code :

            let parent = modalGroup; //phaser group
            let bounds = new Phaser.Rectangle(10, header.bottom, this.game.world.width - 30, this.game.world.height - 150);
            let options = {
                direction: 'y',
                overflow: 50,
                padding: 10
            }
            let listView = new Scroller.ListView(this.game, parent, bounds, options)

            EquimpentSheet.forEach((e, i)=>{
                let bg = this.game.add.graphics(bounds.x, bounds.top + 110 * i);
                bg.beginFill(0xbfbdb3);
                bg.drawRect(0, 0, this.game.world.width - 20, 100);
                bg.anchor.setTo(0.5);
                bg.inputEnabled = true;
                bg.events.onInputDown.add(()=>{
                    this.player.buyItem(e);
                });
                modalGroup.add(bg);
                listView.addMultiple(bg);
                bg.endFill();
            });
QuipHop commented 7 years ago

UPDATE: Click will fire if make click on the parent where item is overflowed

QuipHop commented 7 years ago

Ok, i've found solution According to Your example from http://mattcolman.com/labs/phaser-list-view/index.html I've moved out text to the img child and give it's input.priorityID to 9999;

drewsilcock commented 7 years ago

For those looking at this now, the solution for ListView is passing in the optionSearchForClicks set to true. This means that the ListView checks for onInputDown and onInputUp events if you only click (don't drag) on the list view. Took me a while to figure this out, so just posting for future reference in case anyone else is looking for such an answer. Example code:

const options = {
    direction: "y",
    overflow: 200,
    padding: 100,
    searchForClicks: true,
};

const listView = new ListView(this.game, parent, bounds, options);
listView.addMultiple(...items);
ankurToko commented 7 years ago

@drewsilcock I want to make use of onclick for the list items but this is not helping me.

mattcolman commented 7 years ago

Thanks @drewsilcock for pointing out that searchForClicks is hidden. Just added docs for this https://github.com/mattcolman/phaser-list-view/commit/f12e72bc40db35fd58b4475c0c8c9e49095fff1b

ankurToko commented 7 years ago

Hi @mattcolman is searchForClicks working for 1.0.1

mattcolman commented 7 years ago

probably not. We're at version 1.3.0. Can you upgrade and try?

ankurToko commented 7 years ago

I was unable to make the listview work with the latest version hence had to fall back to the initial version which I got working, but now I need onClick listener for the list items.

mattcolman commented 7 years ago

I think best option is to get 1.3.0 working. Maybe post some code and we can work out why it's not working for you.

ankurToko commented 7 years ago

Do you have any working example for the latest version 1.3.0 ?

mattcolman commented 7 years ago

I can find one. Are you using npm or script tag?

ankurToko commented 7 years ago

Npm

mattcolman commented 7 years ago

@ankurToko thanks for reporting the problem. Imports were not working in 1.3.0 when I started supporting script tag. Fixed now in 1.3.1. Also added an example repo here https://github.com/mattcolman/phaser-list-view-example

ankurToko commented 7 years ago

Thanks @mattcolman , after the fix it works fine. Cheers!