# Class: Particle

## Phaser. Particle

Create a new `Particle` object. Particles are extended Sprites that are emitted by a particle emitter such as Phaser.Particles.Arcade.Emitter.

#### new Particle(game, x, y, key, frame)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | A reference to the currently running game.
  `x` | number | The x coordinate (in world space) to position the Particle at.
  `y` | number | The y coordinate (in world space) to position the Particle at.
  `key` | string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | This is the image or texture used by the Particle during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
  `frame` | string | number | If this Particle is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.

  Source:
    - gameobjects/Particle.js, line 20

### Extends

- Phaser.Sprite

### Members

#### <protected> alphaData

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `alphaData` | array | A reference to the alphaData array owned by the Emitter that emitted this Particle.

  Source:
    - gameobjects/Particle.js, line 52

#### angle

  Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90. If you wish to work in radians instead of degrees use the property Sprite.rotation instead. Working in radians is also a little faster as it doesn't have to convert the angle.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `angle` | number | The angle of this Sprite in degrees.

  Inherited From:
    - Phaser.Sprite#angle
  Source:
    - gameobjects/Sprite.js, line 709

#### animations

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `animations` | Phaser.AnimationManager | This manages animations of the sprite. You can modify animations through it (see Phaser.AnimationManager)

  Inherited From:
    - Phaser.Sprite#animations
  Source:
    - gameobjects/Sprite.js, line 61

#### <protected> autoAlpha

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `autoAlpha` | boolean | If this Particle automatically changes alpha this is set to true by Particle.setAlphaData.

  Source:
    - gameobjects/Particle.js, line 46

#### autoCull

  Should this Sprite be automatically culled if out of range of the camera? A culled sprite has its renderable property set to 'false'. Be advised this is quite an expensive operation, as it has to calculate the bounds of the object every frame, so only enable it if you really need it.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `autoCull` | boolean | A flag indicating if the Sprite should be automatically camera culled or not.

  Inherited From:
    - Phaser.Sprite#autoCull
  Default Value:
    - false
  Source:
    - gameobjects/Sprite.js, line 99

#### <protected> autoScale

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `autoScale` | boolean | If this Particle automatically scales this is set to true by Particle.setScaleData.

  Source:
    - gameobjects/Particle.js, line 28

#### body

  By default Sprites won't add themselves to any physics system and their physics body will be `null`. To enable them for physics you need to call `game.physics.enable(sprite, system)` where `sprite` is this object and `system` is the Physics system you want to use to manage this body. Once enabled you can access all physics related properties via `Sprite.body`.

  Important: Enabling a Sprite for P2 or Ninja physics will automatically set `Sprite.anchor` to 0.5 so the physics body is centered on the Sprite. If you need a different result then adjust or re-create the Body shape offsets manually, and/or reset the anchor after enabling physics.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `body` | Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | null |

  Inherited From:
    - Phaser.Sprite#body
  Default Value:
    - null
  Source:
    - gameobjects/Sprite.js, line 117

#### cameraOffset

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `cameraOffset` | Phaser.Point | If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.

  Inherited From:
    - Phaser.Sprite#cameraOffset
  Source:
    - gameobjects/Sprite.js, line 156

#### checkWorldBounds

  If true the Sprite checks if it is still within the world each frame, when it leaves the world it dispatches Sprite.events.onOutOfBounds and optionally kills the sprite (if Sprite.outOfBoundsKill is true). By default this is disabled because the Sprite has to calculate its bounds every frame to support it, and not all games need it. Enable it by setting the value to true.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `checkWorldBounds` | boolean |

  Inherited From:
    - Phaser.Sprite#checkWorldBounds
  Default Value:
    - false
  Source:
    - gameobjects/Sprite.js, line 139

#### debug

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debug` | boolean | Handy flag to use with Game.enableStep

  Inherited From:
    - Phaser.Sprite#debug
  Default Value:
    - false
  Source:
    - gameobjects/Sprite.js, line 151

#### <readonly> deltaX

  Returns the delta x value. The difference between world.x now and in the previous step.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `deltaX` | number | The delta value. Positive if the motion was to the right, negative if to the left.

  Inherited From:
    - Phaser.Sprite#deltaX
  Source:
    - gameobjects/Sprite.js, line 733

#### <readonly> deltaY

  Returns the delta y value. The difference between world.y now and in the previous step.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `deltaY` | number | The delta value. Positive if the motion was downwards, negative if upwards.

  Inherited From:
    - Phaser.Sprite#deltaY
  Source:
    - gameobjects/Sprite.js, line 750

#### <readonly> deltaZ

  Returns the delta z value. The difference between rotation now and in the previous step.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `deltaZ` | number | The delta value.

  Inherited From:
    - Phaser.Sprite#deltaZ
  Source:
    - gameobjects/Sprite.js, line 767

#### destroyPhase

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `destroyPhase` | boolean | True if this object is currently being destroyed.

  Inherited From:
    - Phaser.Sprite#destroyPhase
  Source:
    - gameobjects/Sprite.js, line 1072

#### events

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `events` | Phaser.Events | The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.

  Inherited From:
    - Phaser.Sprite#events
  Source:
    - gameobjects/Sprite.js, line 56

#### exists

  Sprite.exists controls if the core game loop and physics update this Sprite or not. When you set Sprite.exists to false it will remove its Body from the physics world (if it has one) and also set Sprite.visible to false. Setting Sprite.exists to true will re-add the Body to the physics world (if it has a body) and set Sprite.visible to true.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `exists` | boolean | If the Sprite is processed by the core game update and physics.

  Inherited From:
    - Phaser.Sprite#exists
  Source:
    - gameobjects/Sprite.js, line 906

#### fixedToCamera

  An Sprite that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Sprite.cameraOffset. Note that the cameraOffset values are in addition to any parent in the display list. So if this Sprite was in a Group that has x: 200, then this will be added to the cameraOffset.x

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `fixedToCamera` | boolean | Set to true to fix this Sprite to the Camera at its current world coordinates.

  Inherited From:
    - Phaser.Sprite#fixedToCamera
  Source:
    - gameobjects/Sprite.js, line 953

#### frame

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `frame` | number | Gets or sets the current frame index and updates the Texture Cache for display.

  Inherited From:
    - Phaser.Sprite#frame
  Source:
    - gameobjects/Sprite.js, line 818

#### frameName

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `frameName` | string | Gets or sets the current frame name and updates the Texture Cache for display.

  Inherited From:
    - Phaser.Sprite#frameName
  Source:
    - gameobjects/Sprite.js, line 834

#### game

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | A reference to the currently running Game.

  Inherited From:
    - Phaser.Sprite#game
  Source:
    - gameobjects/Sprite.js, line 34

#### health

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `health` | number | Health value. Used in combination with damage() to allow for quick killing of Sprites.

  Inherited From:
    - Phaser.Sprite#health
  Source:
    - gameobjects/Sprite.js, line 122

#### <readonly> inCamera

  Checks if the Sprite bounds are within the game camera, otherwise false if fully outside of it.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `inCamera` | boolean | True if the Sprite bounds is within the game camera, even if only partially. Otherwise false if fully outside of it.

  Inherited From:
    - Phaser.Sprite#inCamera
  Source:
    - gameobjects/Sprite.js, line 801

#### input

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `input` | Phaser.InputHandler | null | The Input Handler for this object. Needs to be enabled with image.inputEnabled = true before you can use it.

  Inherited From:
    - Phaser.Sprite#input
  Source:
    - gameobjects/Sprite.js, line 104

#### inputEnabled

  By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is activated for this object and it will then start to process click/touch events and more.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `inputEnabled` | boolean | Set to true to allow this object to receive input events.

  Inherited From:
    - Phaser.Sprite#inputEnabled
  Source:
    - gameobjects/Sprite.js, line 865

#### <readonly> inWorld

  Checks if the Sprite bounds are within the game world, otherwise false if fully outside of it.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `inWorld` | boolean | True if the Sprite bounds is within the game world, even if only partially. Otherwise false if fully outside of it.

  Inherited From:
    - Phaser.Sprite#inWorld
  Source:
    - gameobjects/Sprite.js, line 784

#### key

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `key` | string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.

  Inherited From:
    - Phaser.Sprite#key
  Source:
    - gameobjects/Sprite.js, line 66

#### lifespan

  If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc. The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `lifespan` | number | The lifespan of the Sprite (in ms) before it will be killed.

  Inherited From:
    - Phaser.Sprite#lifespan
  Default Value:
    - 0
  Source:
    - gameobjects/Sprite.js, line 130

#### name

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `name` | string | The user defined name given to this Sprite.

  Inherited From:
    - Phaser.Sprite#name
  Source:
    - gameobjects/Sprite.js, line 40

#### outOfBoundsKill

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `outOfBoundsKill` | boolean | If true Sprite.kill is called as soon as Sprite.inWorld returns false, as long as Sprite.checkWorldBounds is true.

  Inherited From:
    - Phaser.Sprite#outOfBoundsKill
  Default Value:
    - false
  Source:
    - gameobjects/Sprite.js, line 145

#### <readonly> renderOrderID

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `renderOrderID` | number | The render order ID, reset every frame.

  Inherited From:
    - Phaser.Sprite#renderOrderID
  Source:
    - gameobjects/Sprite.js, line 850

#### <protected> scaleData

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `scaleData` | array | A reference to the scaleData array owned by the Emitter that emitted this Particle.

  Source:
    - gameobjects/Particle.js, line 34

#### smoothed

  Enable or disable texture smoothing for this Sprite. Only works for bitmap/image textures. Smoothing is enabled by default.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `smoothed` | boolean | Set to true to smooth the texture of this Sprite, or false to disable smoothing (great for pixel art)

  Inherited From:
    - Phaser.Sprite#smoothed
  Source:
    - gameobjects/Sprite.js, line 984

#### <readonly> type

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `type` | number | The const type of this object.

  Inherited From:
    - Phaser.Sprite#type
  Source:
    - gameobjects/Sprite.js, line 46

#### world

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `world` | Phaser.Point | The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.

  Inherited From:
    - Phaser.Sprite#world
  Source:
    - gameobjects/Sprite.js, line 89

#### x

  The position of the Sprite on the x axis relative to the local coordinates of the parent.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `x` | number | The position of the Sprite on the x axis relative to the local coordinates of the parent.

  Inherited From:
    - Phaser.Sprite#x
  Source:
    - gameobjects/Sprite.js, line 1018

#### y

  The position of the Sprite on the y axis relative to the local coordinates of the parent.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `y` | number | The position of the Sprite on the y axis relative to the local coordinates of the parent.

  Inherited From:
    - Phaser.Sprite#y
  Source:
    - gameobjects/Sprite.js, line 1045

#### z

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `z` | number | The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.

  Inherited From:
    - Phaser.Sprite#z
  Source:
    - gameobjects/Sprite.js, line 51

### Methods

#### bringToTop()

  Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only bought to the top of that Group, not the entire display list.

  Inherited From:
    - Phaser.Sprite#bringToTop
  Source:
    - gameobjects/Sprite.js, line 653

  ##### Returns:

  (Phaser.Sprite) This instance.

#### crop(rect)

  Crop allows you to crop the texture used to display this Sprite. Cropping takes place from the top-left of the Sprite and can be modified in real-time by providing an updated rectangle object. Note that cropping a Sprite will reset its animation to the first frame. You cannot currently crop an animated Sprite. The rectangle object given to this method can be either a Phaser.Rectangle or any object so long as it has public x, y, width and height properties. Please note that the rectangle object given is not duplicated by this method, but rather the Image uses a reference to the rectangle. Keep this in mind if assigning a rectangle in a for-loop, or when cleaning up for garbage collection.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `rect` | Phaser.Rectangle | The Rectangle to crop the Sprite to. Pass null or no parameters to clear a previously set crop rectangle.

  Inherited From:
    - Phaser.Sprite#crop
  Source:
    - gameobjects/Sprite.js, line 409

#### damage(amount)

  Damages the Sprite, this removes the given amount from the Sprites health property. If health is then taken below or is equal to zero `Sprite.kill` is called.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `amount` | number | The amount to subtract from the Sprite.health value.

  Inherited From:
    - Phaser.Sprite#damage
  Source:
    - gameobjects/Sprite.js, line 590

  ##### Returns:

  (Phaser.Sprite) This instance.

#### destroy(destroyChildren)

  Destroys the Sprite. This removes it from its parent group, destroys the input, event and animation handlers if present and nulls its reference to game, freeing it up for garbage collection.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `destroyChildren` | boolean | <optional> | true | Should every child of this object have its destroy method called?

  Inherited From:
    - Phaser.Sprite#destroy
  Source:
    - gameobjects/Sprite.js, line 513

#### kill()

  Kills a Sprite. A killed Sprite has its alive, exists and visible properties all set to false. It will dispatch the onKilled event, you can listen to Sprite.events.onKilled for the signal. Note that killing a Sprite is a way for you to quickly recycle it in a Sprite pool, it doesn't free it up from memory. If you don't need this Sprite any more you should call Sprite.destroy instead.

  Inherited From:
    - Phaser.Sprite#kill
  Source:
    - gameobjects/Sprite.js, line 488

  ##### Returns:

  (Phaser.Sprite) This instance.

#### loadTexture(key, frame)

  Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache. This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
  `frame` | string | number | If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.

  Inherited From:
    - Phaser.Sprite#loadTexture
  Source:
    - gameobjects/Sprite.js, line 337

#### onEmit()

  Called by the Emitter when this particle is emitted. Left empty for you to over-ride as required.

  Source:
    - gameobjects/Particle.js, line 103

#### overlap(displayObject) → {boolean}

  Checks to see if the bounds of this Sprite overlaps with the bounds of the given Display Object, which can be a Sprite, Image, TileSprite or anything that extends those such as a Button. This check ignores the Sprites hitArea property and runs a Sprite.getBounds comparison on both objects to determine the result. Therefore it's relatively expensive to use in large quantities (i.e. with lots of Sprites at a high frequency), but should be fine for low-volume testing where physics isn't required.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `displayObject` | Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject | The display object to check against.

  Inherited From:
    - Phaser.Sprite#overlap
  Source:
    - gameobjects/Sprite.js, line 693

  ##### Returns:

  True if the bounds of this Sprite intersects at any point with the bounds of the given display object.

  Type
    boolean

#### play(name, frameRate, loop, killOnComplete) → {Phaser.Animation}

  Play an animation based on the given key. The animation should previously have been added via sprite.animations.add() If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `name` | string |  |  | The name of the animation to be played, e.g. "fire", "walk", "jump".
  `frameRate` | number | <optional> | null | The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
  `loop` | boolean | <optional> | false | Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
  `killOnComplete` | boolean | <optional> | false | If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.

  Inherited From:
    - Phaser.Sprite#play
  Source:
    - gameobjects/Sprite.js, line 672

  ##### Returns:

  A reference to playing Animation instance.

  Type
    Phaser.Animation

#### postUpdate()

  Internal function called by the World postUpdate cycle.

  Inherited From:
    - Phaser.Sprite#postUpdate
  Source:
    - gameobjects/Sprite.js, line 304

#### preUpdate() → {boolean}

  Automatically called by World.preUpdate.

  Inherited From:
    - Phaser.Sprite#preUpdate
  Source:
    - gameobjects/Sprite.js, line 185

  ##### Returns:

  True if the Sprite was rendered, otherwise false.

  Type
    boolean

#### reset(x, y, health)

  Resets the Particle. This places the Particle at the given x/y world coordinates and then sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state and health values. If the Particle has a physics body that too is reset.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `x` | number |  |  | The x coordinate (in world space) to position the Particle at.
  `y` | number |  |  | The y coordinate (in world space) to position the Particle at.
  `health` | number | <optional> | 1 | The health to give the Particle.

  Source:
    - gameobjects/Particle.js, line 142

  ##### Returns:

  (Phaser.Particle) This instance.

#### revive(health)

  Brings a 'dead' Sprite back to life, optionally giving it the health value specified. A resurrected Sprite has its alive, exists and visible properties all set to true. It will dispatch the onRevived event, you can listen to Sprite.events.onRevived for the signal.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `health` | number | <optional> | 1 | The health to give the Sprite.

  Inherited From:
    - Phaser.Sprite#revive
  Source:
    - gameobjects/Sprite.js, line 460

  ##### Returns:

  (Phaser.Sprite) This instance.

#### setAlphaData()

  Called by the Emitter if autoAlpha has been enabled. Passes over the alpha ease data and resets the alpha counter.

  Source:
    - gameobjects/Particle.js, line 112

#### setScaleData()

  Called by the Emitter if autoScale has been enabled. Passes over the scale ease data and resets the scale counter.

  Source:
    - gameobjects/Particle.js, line 127

#### update()

  Updates the Particle scale or alpha if autoScale and autoAlpha are set.

  Source:
    - gameobjects/Particle.js, line 65