Jump to content

Phaser 3 Group


Appolos
 Share

Recommended Posts

Hello !

I created a group in my game, and I have arrows (left / right), and that's what I can not do:

1. I need to select only one element at a given time.

2. After pressing the left or right arrow, I need to move one element of the group to the next (for example, a slider).

 

Please help to do this! Thanks !)

Here is my code:

  this.rightArrow= this.add.sprite(game.config.width / 2+280, game.config.height/2,'rightArrow')
            .setScale(0.3)
            .setInteractive()
            .customParams = {direction:-1}
        this.left= this.add.sprite(game.config.width / 2-280, game.config.height/2,'rightArrow')
            .setScale(-0.3)
            .setInteractive()
            .customParams = {direction:1}

        let knifeData = [{
                key: 'knife1',
                text: 'Areos',
                price: 100,
            },
            {
                key: 'knife2',
                text: 'Winter',
                price: 100,
            },
            {
                key: 'knife3',
                text: 'Scalpel',
                price: 100,
            },
            {
                key: 'knife4',
                text: 'Hunting Knife',
                price: 100,
            },
            {
                key: 'knife5',
                text: 'Bayonets',
                price: 100,
            }
    ]
        this.group = this.add.group();
        knifeData.forEach(element => {
            this.group.create(game.config.width / 2, game.config.height / 2, element.key)
            this.group.create(game.config.width / 2, game.config.height / 2, element.key)
            this.group.create(game.config.width / 2, game.config.height / 2, element.key)
            this.group.create(game.config.width / 2, game.config.height / 2, element.key)
            this.group.create(game.config.width / 2, game.config.height / 2, element.key)
        })

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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