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

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...
 Share

  • Recently Browsing   0 members

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