Sign in to follow this  
Appolos

Phaser 3 Group

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)
        })

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.