Jump to content

Boucing Phaser


Breno Pinheiro
 Share

Recommended Posts

Hello, I studying how to create a game like 8 ball pool game. But when the ball collides on the world bounds, the bouncing effect dont work.

 

GameStates.Game = function (game) {

};

GameStates.Game.prototype = {

    create: function () {

        this.physics.startSystem(Phaser.Physics.ARCADE);
        
        this.stage.backgroundColor = '#124184';

        forca_x_ini = 0;
        forca_y_ini = 0;

        forca_x_fim = 0;
        forca_y_fim = 0;

        forca_total_x = 0;
        forca_total_y = 0;

        line = null;
        
        

        bolas = this.add.group();

            //below code creates a simple tween animation. You will want to delete this when adding your code
            logo = this.add.sprite(this.world.centerX, this.world.centerY, 'logo');
            logo.inputEnabled = true;
            logo.events.onInputDown.add(function (sprite, pointer) {

                forca_x_ini = pointer.x;
                forca_y_ini = pointer.y;

                console.log('Inicia: x:'+forca_x_ini +' Y:'+forca_y_ini);

            }, this);
            logo.events.onInputUp.add(function (sprite, pointer) {
                forca_x_fim = pointer.x;
                forca_y_fim = pointer.y;

                console.log('Fim: x:' + forca_x_fim + ' Y:' + forca_y_fim);

                forca_total_x = (forca_x_ini - forca_x_fim);
                forca_total_y = (forca_y_ini - forca_y_fim);

            }, this);
            logo.scale.setTo(0.5, 0.5);
            logo.anchor.setTo(0.5, 0.5);
            this.physics.arcade.enable(logo);
            logo.body.collideWorldBounds = true;
            logo.body.bounce.set(1);
        
        //this.camera.follow(logo);
        
    },

    update: function () {
        
        console.log();
        logo.body.velocity.x = forca_total_x;
        logo.body.velocity.y = forca_total_y;

       forca_total_x *= 0.99;
       forca_total_y *= 0.99;
    },
    mouseDown: function() {
    },
    mouseUp: function() {
    },

    render: function () { },
};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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