Class/Object

io.scalajs.dom.html.phaser

Weapon

Related Docs: object Weapon | package phaser

Permalink

class Weapon extends Object

The Weapon Plugin provides the ability to easily create a bullet pool and manager.

Weapons fire Phaser.Bullet objects, which are essentially Sprites with a few extra properties. The Bullets are enabled for Arcade Physics. They do not currently work with P2 Physics.

The Bullets are created inside of Weapon.bullets, which is a Phaser.Group instance. Anything you can usually do with a Group, such as move it around the display list, iterate it, etc can be done to the bullets Group too.

Bullets can have textures and even animations. You can control the speed at which they are fired, the firing rate, the firing angle, and even set things like gravity for them.

A small example, assumed to be running from within a Phaser.State create method.

Annotations
@RawJSType() @native() @JSName( "Phaser.Weapon" )
See also

http://phaser.io/docs/2.6.2/Phaser.Weapon.html

Linear Supertypes
Object, Any, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Weapon
  2. Object
  3. Any
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Weapon(game: Phaser.Game, parent: Phaser.PluginManager)

    Permalink

    game

    A reference to the current Phaser.Game instance.

    parent

    The Phaser Plugin Manager which looks after this plugin.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def addBulletAnimation(name: String, frames: Array[|[String, JsNumber]] = js.native, frameRate: Double = js.native, loop: Boolean = js.native, useNumericIndex: Boolean = js.native): Phaser.Weapon

    Permalink

    Adds a new animation under the given key.

    Adds a new animation under the given key. Optionally set the frames, frame rate and loop. The arguments are all the same as for Animation.add, and work in the same way. Weapon.bulletAnimation will be set to this animation after it's created. From that point on, all

    bullets fired will play using this animation. You can swap between animations by calling this method several times, and then just changing the Weapon.bulletAnimation property to the name of the animation you wish to play for the next launched bullet. If you wish to stop using animations at all, set Weapon.bulletAnimation to "" (an empty string).

    name

    The unique (within the Weapon instance) name for the animation, i.e. "fire", "blast".

    frames

    An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.

    frameRate

    The speed at which the animation should play. The speed is given in frames per second.

    loop

    Whether or not the animation is looped or just plays once.

    useNumericIndex

    Are the given frames using numeric indexes (default) or strings?

    returns

    The Weapon Plugin.

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. var autoExpandBulletsGroup: Boolean

    Permalink

    Should the bullet pool run out of bullets (i.e.

    Should the bullet pool run out of bullets (i.e. they are all in flight) then this boolean controls if the Group will create a brand new bullet object or not.

  7. var autofire: Boolean

    Permalink

    Will this weapon auto fire? If set to true then a new bullet will be fired based on the fireRate value.

  8. var bounds: Phaser.Rectangle

    Permalink

    This Rectangle defines the bounds that are used when determining if a Bullet should be killed or not.

    This Rectangle defines the bounds that are used when determining if a Bullet should be killed or not. It's used in combination with Weapon.bulletKillType when that is set to either Phaser.Weapon.KILL_WEAPON_BOUNDS or Phaser.Weapon.KILL_STATIC_BOUNDS. If you are not using either of these kill types then the bounds are ignored. If you are tracking a Sprite or Point then the bounds are centered on that object every frame.

  9. var bulletAnimation: String

    Permalink

    The string based name of the animation that the Bullet will be given on launch.

    The string based name of the animation that the Bullet will be given on launch. This is set via Weapon.addBulletAnimation.

  10. var bulletClass: Object

    Permalink

    The Class of the bullets that are launched by this Weapon.

    The Class of the bullets that are launched by this Weapon. Defaults Phaser.Bullet, but can be overridden before calling createBullets and set to your own class type.

  11. var bulletCollideWorldBounds: Boolean

    Permalink

    Should bullets collide with the World bounds or not?

  12. var bulletFrame: |[String, Int]

    Permalink

    The Texture Frame that the Bullets use when rendering.

    The Texture Frame that the Bullets use when rendering. Changing this has no effect on bullets in-flight, only on newly spawned bullets.

  13. var bulletFrameCycle: Boolean

    Permalink

    If you've added a set of frames via Weapon.setBulletFrames then you can optionally chose for each Bullet fired to use the next frame in the set.

    If you've added a set of frames via Weapon.setBulletFrames then you can optionally chose for each Bullet fired to use the next frame in the set. The frame index is then advanced one frame until it reaches the end of the set, then it starts from the start again. Cycling frames like this allows you to create varied bullet effects via sprite sheets.

  14. var bulletFrameRandom: Boolean

    Permalink

    If you've added a set of frames via Weapon.setBulletFrames then you can optionally chose for each Bullet fired to pick a random frame from the set.

  15. var bulletGravity: Phaser.Point

    Permalink

    This is the amount of gravity added to the Bullets physics body when fired.

    This is the amount of gravity added to the Bullets physics body when fired. Gravity is expressed in pixels / second / second.

  16. var bulletInheritSpriteSpeed: Boolean

    Permalink

    When a Bullet is fired it can optionally inherit the velocity of the trackedSprite if set.

  17. var bulletKey: String

    Permalink

    If you've set bulletKillType to Phaser.Weapon.KILL_DISTANCE this controls the distance the Bullet can travel before it is automatically killed.

    If you've set bulletKillType to Phaser.Weapon.KILL_DISTANCE this controls the distance the Bullet can travel before it is automatically killed. The distance is given in pixels.

  18. var bulletKillDistance: Double

    Permalink

    If you've set bulletKillType to Phaser.Weapon.KILL_DISTANCE this controls the distance the Bullet can travel before it is automatically killed.

    If you've set bulletKillType to Phaser.Weapon.KILL_DISTANCE this controls the distance the Bullet can travel before it is automatically killed. The distance is given in pixels.

  19. var bulletKillType: Int

    Permalink

    This controls how the bullets will be killed.

    This controls how the bullets will be killed. The default is Phaser.Weapon.KILL_WORLD_BOUNDS.

    There are 7 different "kill types" available:

    See also

    Phaser.Weapon.KILL_STATIC_BOUNDS

    Phaser.Weapon.KILL_WORLD_BOUNDS

    Phaser.Weapon.KILL_CAMERA_BOUNDS

    Phaser.Weapon.KILL_WEAPON_BOUNDS

    Phaser.Weapon.KILL_DISTANCE

    Phaser.Weapon.KILL_LIFESPAN

    Phaser.Weapon.KILL_NEVER

  20. var bulletLifespan: Double

    Permalink

    If you've set bulletKillType to Phaser.Weapon.KILL_LIFESPAN this controls the amount of lifespan the Bullets have set on launch.

    If you've set bulletKillType to Phaser.Weapon.KILL_LIFESPAN this controls the amount of lifespan the Bullets have set on launch. The value is given in milliseconds. When a Bullet hits its lifespan limit it will be automatically killed.

  21. var bulletRotateToVelocity: Boolean

    Permalink

    Bullets can optionally adjust their rotation in-flight to match their velocity.

    Bullets can optionally adjust their rotation in-flight to match their velocity. This can create the effect of a bullet 'pointing' to the path it is following, for example an arrow being fired from a bow, and works especially well when added to bulletGravity.

  22. var bulletSpeed: Double

    Permalink

    The speed at which the bullets are fired.

    The speed at which the bullets are fired. This value is given in pixels per second, and is used to set the starting velocity of the bullets.

  23. var bulletSpeedVariance: Double

    Permalink

    This is a variance added to the speed of Bullets when they are fired.

    This is a variance added to the speed of Bullets when they are fired. If bullets have a bulletSpeed value of 200, and a bulletSpeedVariance of 50 then the actual speed of the Bullets will be between 150 and 250 pixels per second.

  24. var bulletWorldWrap: Boolean

    Permalink

    Should the Bullets wrap around the world bounds? This automatically calls World.wrap on the Bullet each frame.

    Should the Bullets wrap around the world bounds? This automatically calls World.wrap on the Bullet each frame. See the docs for that method for details.

  25. var bulletWorldWrapPadding: Int

    Permalink

    If bulletWorldWrap is true then you can provide an optional padding value with this property.

    If bulletWorldWrap is true then you can provide an optional padding value with this property. It's added to the calculations determining when the Bullet should wrap around the world or not. The value is given in pixels.

  26. var bullets: Phaser.Group[Phaser.Bullet]

    Permalink

    This is the Phaser.Group that contains all of the bullets managed by this plugin.

  27. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. def createBullets[T](quantity: Int = js.native, key: String = js.native, frame: |[JsNumber, String] = js.native, group: Phaser.Group[T] = js.native): Phaser.Weapon

    Permalink

    This method performs two actions: First it will check to see if the Weapon.bullets Group exists or not, and if not it creates it, adding it the group given as the 4th argument.

    This method performs two actions: First it will check to see if the Weapon.bullets Group exists or not, and if not it creates it, adding it the group given as the 4th argument. Then it will seed the bullet pool with the quantity number of Bullets, using the texture key and frame provided (if any).

    If for example you set the quantity to be 10, then this Weapon will only ever be able to have 10 bullets in-flight simultaneously. If you try to fire an 11th bullet then nothing will happen until one, or more, of the in-flight bullets have been killed, freeing them up for use by the Weapon again. If you do not wish to have a limit set, then pass in -1 as the quantity. In this instance the Weapon will keep increasing the size of the bullet pool as needed. It will never reduce the size of the pool however, so be careful it doesn't grow too large.

    You can either set the texture key and frame here, or via the Weapon.bulletKey and Weapon.bulletFrame properties. You can also animate bullets, or set them to use random frames. All Bullets belonging to a single Weapon instance must share the same texture key however.

    quantity

    The quantity of bullets to seed the Weapon with. If -1 it will set the pool to automatically expand.

    key

    The Game.cache key of the image that this Sprite will use.

    frame

    If the Sprite image contains multiple frames you can specify which one to use here.

    group

    Optional Group to add the object to. If not specified it will be added to the World group.

    returns

    This Weapon instance.

  29. def debug(x: Double = js.native, y: Double = js.native, debugBodies: Boolean = js.native): Unit

    Permalink

    Uses Game.Debug to draw some useful information about this Weapon, including the number of bullets both in-flight, and available.

    Uses Game.Debug to draw some useful information about this Weapon, including the number of bullets both in-flight, and available. And optionally the physics debug bodies of the bullets.

    x

    The coordinate, in screen space, at which to draw the Weapon debug data.

    y

    The coordinate, in screen space, at which to draw the Weapon debug data.

    debugBodies

    Optionally draw the physics body of every bullet in-flight.

  30. def destroy(): Unit

    Permalink

    Destroys this Weapon.

    Destroys this Weapon. It removes itself from the PluginManager, destroys the bullets Group, and nulls internal references.

  31. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  32. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  33. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  34. def fire(from: |[Phaser.Sprite, Phaser.Point] = js.native, x: Double = js.native, y: Double = js.native): Phaser.Bullet

    Permalink
  35. var fireAngle: Double

    Permalink

    The angle at which the bullets are fired.

    The angle at which the bullets are fired. This can be a const such as Phaser.ANGLE_UP or it can be any number from 0 to 360 inclusive, where 0 degrees is to the right.

  36. var fireFrom: Phaser.Rectangle

    Permalink

    This is a Rectangle from within which the bullets are fired.

    This is a Rectangle from within which the bullets are fired. By default it's a 1x1 rectangle, the equivalent of a Point. But you can change the width and height, and if larger than 1x1 it'll pick a random point within the rectangle to launch the bullet from.

  37. var fireLimit: Double

    Permalink

    he maximum number of shots that this Weapon is allowed to fire before it stops.

    he maximum number of shots that this Weapon is allowed to fire before it stops. When the limit is his the Weapon.onFireLimit Signal is dispatched. You can reset the shot counter via Weapon.resetShots.

  38. var fireRate: Double

    Permalink

    The rate at which this Weapon can fire.

    The rate at which this Weapon can fire. The value is given in milliseconds.

  39. var fireRateVariance: Double

    Permalink

    This is a modifier that is added to the fireRate each update to add variety to the firing rate of the Weapon.

    This is a modifier that is added to the fireRate each update to add variety to the firing rate of the Weapon. The value is given in milliseconds. If you've a fireRate of 200 and a fireRateVariance of 50 then the actual firing rate of the Weapon will be between 150 and 250.

  40. var game: Phaser.Game

    Permalink

    A reference to the current Phaser.Game instance.

  41. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  42. def hasOwnProperty(v: String): Boolean

    Permalink
    Definition Classes
    Object
  43. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  44. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  45. def isPrototypeOf(v: Object): Boolean

    Permalink
    Definition Classes
    Object
  46. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  47. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  48. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  49. var onFire: Phaser.Signal

    Permalink

    The onFire Signal is dispatched each time Weapon.fire is called, and a Bullet is successfully launched.

    The onFire Signal is dispatched each time Weapon.fire is called, and a Bullet is successfully launched. The callback is set two arguments: a reference to the bullet sprite itself, and a reference to the Weapon that fired the bullet.

  50. var onFireLimit: Phaser.Signal

    Permalink

    The onFireLimit Signal is dispatched if Weapon.fireLimit is > 0, and a bullet launch takes the number of shots fired to equal the fire limit.

    The onFireLimit Signal is dispatched if Weapon.fireLimit is > 0, and a bullet launch takes the number of shots fired to equal the fire limit. The callback is sent two arguments: A reference to the Weapon that hit the limit, and the value of Weapon.fireLimit.

  51. var onKill: Phaser.Signal

    Permalink

    The onKill Signal is dispatched each time a Bullet that is in-flight is killed.

    The onKill Signal is dispatched each time a Bullet that is in-flight is killed. This can be the result of leaving the Weapon bounds, an expiring lifespan, or exceeding a specified distance. The callback is sent one argument: A reference to the bullet sprite itself.

  52. val parent: Phaser.PluginManager

    Permalink

    The Phaser Plugin Manager which looks after this plugin.

  53. def propertyIsEnumerable(v: String): Boolean

    Permalink
    Definition Classes
    Object
  54. var shots: Double

    Permalink

    The total number of bullets this Weapon has fired so far.

    The total number of bullets this Weapon has fired so far. You can limit the number of shots allowed (via fireLimit), and reset this total via Weapon.resetShots.

  55. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  56. def toLocaleString(): String

    Permalink
    Definition Classes
    Object
  57. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  58. var trackOffset: Phaser.Point

    Permalink

    The Track Offset is a Point object that allows you to specify a pixel offset that bullets use when launching from a tracked Sprite or Pointer.

    The Track Offset is a Point object that allows you to specify a pixel offset that bullets use when launching from a tracked Sprite or Pointer. For example if you've got a bullet that is 2x2 pixels in size, but you're tracking a Sprite that is 32x32, then you can set trackOffset.x = 16 to have the bullet launched from the center of the Sprite.

  59. var trackRotation: Boolean

    Permalink

    If the Weapon is tracking a Sprite, should it also track the Sprites rotation? This is useful for a game such as Asteroids, where you want the weapon to fire based on the sprites rotation.

  60. var trackedPointer: Phaser.Pointer

    Permalink

    The Pointer currently being tracked by the Weapon, if any.

    The Pointer currently being tracked by the Weapon, if any. This is set via the Weapon.trackPointer method.

  61. var trackedSprite: Phaser.Sprite

    Permalink

    The Sprite currently being tracked by the Weapon, if any.

    The Sprite currently being tracked by the Weapon, if any. This is set via the Weapon.trackSprite method.

  62. def valueOf(): Any

    Permalink
    Definition Classes
    Object
  63. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  65. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  66. var x: Double

    Permalink

    The x coordinate from which bullets are fired.

    The x coordinate from which bullets are fired. This is the same as Weapon.fireFrom.x, and can be overridden by the Weapon.fire arguments.

  67. var y: Double

    Permalink

    The y coordinate from which bullets are fired.

    The y coordinate from which bullets are fired. This is the same as Weapon.fireFrom.y, and can be overridden by the Weapon.fire arguments.

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped