Jump to content

Shoot a rope


datahandler
 Share

Recommended Posts

Hi,

I started recreating an arcade game called Pang and have a javascript version (1st level) here

I'd like to use Phaser to continue the development but am stuck on how to animate the weapon (a metal rope with a spearhead).

I'd tried using the Phaser.Rope class but am struggling to understand how to do the following:

  • Add a spearhead to the end of the rope
  • Animate the rope from the player's position to the top of the screen
  • Start the animation when the user presses fire (spacebar)

if anyone could give me any pointers, I'd be eternally grateful!

 

 

Link to comment
Share on other sites

I actually think you shouldn't use Phaser.Rope for this. What you're trying to accomplish for the "rope" part of the entity can easily be done with a simple tilesprite that expands in height over its lifetime, with the spearhead being a "child" to that sprite with its Y offset updated to be half its height. I hope that makes sense, but basically, you'll be using game.add.tilesprite, game.add.sprite, and you'll be calling rope.addChild(spear).

Link to comment
Share on other sites

Hi Tilde

thank you for your reply. I have used tilesprite and addChild to create a 'rope' with a spearhead that fires from the player's position to the top of the screen when the spacebar is pressed.

However, in order to achieve this, I have to set the tilesprite height to a negative value to get it to draw vertically up the screen (as below)

This means that I can't take advantage of outOfBoundsKill or game.physics.arcade.overlap, as the framework does not register the weapon as being in the world!

I'm clearly doing something wrong, but I'm not sure how to correct it?

function updateWeapon() {
    if (weapon.alive && weapon.height - weapon.children[0].height - 100 > game.world.height*-1) {
        weapon.height -= 8;
        weapon.children[0].y -= 8;                
    }
    else weapon.kill();
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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