Jump to content

Extend Weapon Plugin (TypeScript)


Recommended Posts


I'm trying to make separate weapon classes in an Asteroids-type game, for example a Missile.ts, Laser.ts, etc.

What I have so far is this (Missile.ts):

module Spaceroni {

    export class Missile extends Phaser.Weapon {

        constructor(game: Phaser.Game) {

            super(game, game.plugins);
            this.bulletKillType = Phaser.Weapon.KILL_LIFESPAN;
            this.bulletSpeed = 1500;
            this.fireRate = 20;




In my Player.ts I have

weapon: Spaceroni.Missile;

up top and I'm adding a weapon in its constructor with

this.weapon = game.add.weapon(30, 'missile');

This isn't working (bulletSpeed and fireRate aren't changing), I think because game.add.weapon() creates a new weapon instance, separate from my Missile class. I would like to avoid putting all of this Missile-specific code directly into the Player class since I want to be able to change the weapon based on power-ups, as well as add the Missile weapon to enemies.

Any ideas on how to properly extend the weapon plugin?

Thanks in advance!

Link to comment
Share on other sites

Hi, you need a helper similar to game.add.weapon:

Phaser.GameObjectFactory.prototype.missile = function (quantity, key, frame, group) {
  var missile = this.game.plugins.add(Spaceroni.Missile);

  missile.createBullets(quantity, key, frame, group);

  return missile;

// …

this.weapon = game.add.missile(30, 'missile');


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.

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.


  • Recently Browsing   0 members

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