Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

P2JS shoot the pointer


przemoo83
 Share

Recommended Posts

  • 1 year later...

Arcade is faster. If you need better performance (maybe for mobile, old computers or very complex games) stay with arcade (in good computers and/or in simple games you dont will feel any difference). But, arcade works only with rectangles so, if you need to collide with balls or something complexer you possible will dont have a good effect with arcade.

I have a simple game made with P2JS and an older version made with arcade, you can see the difference between the ball collision with the basket.

P2JS

http://funs2.com/funs2/games/freethrow/

Arcade

http://funs2.com/funs2/games/freethrowarcade/

I changed my P2JS code to make it have a similar effect as moveToPointer() example (http://phaser.io/examples/v2/arcade-physics/move-to-pointer).

You can see it running here (http://funs2.com/funs2/games/pointer_example/).

create : function()
    {   
        this.canmove=false;
        this.baskball = this.game.add.sprite(this.game.world.centerX,this.game.world.centerY+(this.game.world.centerY/2),'ball');
        this.game.physics.startSystem(Phaser.Physics.P2JS);
        this.game.physics.p2.gravity.y = 0;
        this.game.physics.p2.enable(this.baskball);
        this.baskball.body.setCircle(30);
        this.baskball.anchor.setTo(0.5, 0.5); 
        this.baskball.body.moves = false;
        this.baskball.body.allowGravity = false;
        this.baskball.body.static = true;
        this.input.onDown.add(this.move, this);
    },
    
    move : function() {
        this.baskball.body.velocity.x=this.game.input.activePointer.worldX-this.baskball.x;
        this.baskball.body.velocity.y=this.game.input.activePointer.worldY-this.baskball.y;
        this.canmove = true;
    },

    update : function()
    {
        if (this.canmove == true)
        {
            this.baskball.x = this.game.input.activePointer.worldX;   
            this.baskball.y = this.game.input.activePointer.worldY;
        }
    }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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