Jump to content

Apply physics to objets in group (Bullets)


Recommended Posts

I am very new in the html5 and game development and I am very impressed with the engines, specially Phaser.


I am developing a 2D game based on the Tank example available at http://examples.phaser.io/.

Currently, I am trying to physics to the bullet group, but I read in the post from yesterday that is not possible http://www.html5gamedevs.com/topic/4800-how-to-add-velocity-to-a-group/.


The idea is to shoot when when clicked and the bullets should lose height and speed as it cross the screen.

Here is revelant part of the code:

function create() {...    //  Our bullet group    bullets = game.add.group();    bullets.createMultiple(30, 'dude');    bullets.setAll('anchor.x', 0.5);    bullets.setAll('anchor.y', 0.5);    bullets.setAll('outOfBoundsKill', true);
function update() {    if (game.input.activePointer.isDown)    {        //  Boom!        fire();    }}function fire () {    if (game.time.now > nextFire && bullets.countDead() > 0)    {        nextFire = game.time.now + fireRate;        var bullet = bullets.getFirstDead();        bullet.reset(weapon.x, weapon.y);               bullet.rotation = game.physics.moveToPointer(bullet, 1000);    }}

Any idea of how to implement it ?



Link to comment
Share on other sites


  • Recently Browsing   0 members

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