Jump to content

the ball does not function as desired when clicked on the desired button, Phaser 3


arif
 Share

Recommended Posts

there seems to be something wrong with the code, one button has to slow down and one button to speed up when I add this code,
 

this.downButton = this.add.image(80, 530, 'up-bubble').setInteractive();
    this.upButton = this.add.image(230, 530, 'down-bubble').setInteractive();
    this.input.on('gameobjectup', function (pointer, gameobject) {

        if (gameobject === this.downButton && this.spinSpeed > 0)
        {
            this.spinSpeed -= 0.1;
        }
        else if (gameobject === this.upButton && this.spinSpeed < 9.9)
        {
            this.spinSpeed += 0.1;
        }

    });   

but, when I add this code between generateBalls (), it doesn't work at all, it doesn't work,

generateBalls() {

    const hitArea = new Phaser.Geom.Rectangle(0, 0, 32, 32);
    const hitAreaCallback = Phaser.Geom.Rectangle.Contains;        

    const circle = new Phaser.Geom.Circle(400, 300, 220);
    const balls  = this.add.group(null, { 
        key: 'balls', 
        frame: [0, 1, 5], 
        repeat: 5, 
        setScale: { x: 3, y: 3 },
        hitArea: hitArea,
        hitAreaCallback: hitAreaCallback,
    });

    this.downButton = this.add.image(80, 530, 'up-bubble').setInteractive();
    this.upButton = this.add.image(230, 530, 'down-bubble').setInteractive();
    this.input.on('gameobjectup', function (pointer, gameobject) {

        if (gameobject === this.downButton && this.spinSpeed > 0)
        {
            this.spinSpeed -= 0.1;
        }
        else if (gameobject === this.upButton && this.spinSpeed < 9.9)
        {
            this.spinSpeed += 0.1;
        }

    });       

    Phaser.Actions.PlaceOnCircle( balls.getChildren(), circle);
    return balls;
}
 generateDance() {
        this.spinSpeed = 0.003;  
        return this.tweens.addCounter({
            from: 220,
            to: 160,
            duration: 9000,
            delay: 2000,
            ease: 'Sine.easeInOut',
            repeat: -1,
            yoyo: true
        });
    }
update() {

    this.playerEyes.update();
    Phaser.Actions.RotateAroundDistance( this.balls.getChildren(), { x: 400, y: 300 }, this.spinSpeed, this.dance.getValue());
}

I took the code from the Phaser 3 example this is https://phaser.io/examples/v3/view/tweens/tween-time-scale

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