Options
All
  • Public
  • Public/Protected
  • All
Menu

An Entity that has a body and allows easy management of the childrens bodies.

Hierarchy

Index

Constructors

constructor

  • new PhysicsEntity(game: Phaser.Game, x: number, y: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number): PhysicsEntity
  • Parameters

    • game: Phaser.Game

      Reference to Phaser game used internally.

    • x: number

      X position of the object on the screen.

    • y: number

      Y position of the object on the screen.

    • Optional key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture

      Key of the image in the phaser cache. Optional.

    • Optional frame: string | number

      Frame of image in spritesheet. Optional.

    Returns PhysicsEntity

Properties

MaxVelocity

MaxVelocity: number = -1

Private _childConstraints

_childConstraints: Phaser.Physics.P2.LockConstraint[]

Protected _children

_children: Phaser.Sprite[]

Protected _circleRadius

_circleRadius: number

body

body: Phaser.Physics.P2.Body

game

Accessors

Id

  • get Id(): number
  • The unique ID of this shared object.

    Returns number

OnDestroyedEvent

Radius

  • get Radius(): number
  • Returns number

Tags

  • get Tags(): string[]
  • Gets all tags of this SharedObject.

    Returns string[]

children

  • get children(): Phaser.Sprite[]
  • Returns all the children of this entity.

    Returns Phaser.Sprite[]

Protected objectCache

scale

  • set scale(scale: Phaser.Point): void
  • Set the scale of this entity and all it's children.

    Parameters

    • scale: Phaser.Point

    Returns void

Static IsLocalStorageSupported

  • get IsLocalStorageSupported(): boolean

Static Private PHYSICS_DEBUG_ENABLED

  • get PHYSICS_DEBUG_ENABLED(): boolean
  • Is the Phaser physics debug mode enabled on new physics bodies?

    Returns boolean

Methods

AddTag

  • AddTag(tag: string): void
  • Add a tag to this SharedObject which can be used to find other SharedObjects with certain tags. Will silently fail if tag is already present on this SharedObject.

    Parameters

    • tag: string

      Tag to add.

    Returns void

AttachChild

  • AttachChild(child: Phaser.Sprite): Phaser.Sprite
  • Attaches the given child to this object. This is not the same as using addChild(child). This entities scale will be applied to the child when calling this method. Returns the added child.

    Parameters

    • child: Phaser.Sprite

      Sprite to child.

    Returns Phaser.Sprite

Private ConstrainVelocity

  • ConstrainVelocity(): void
  • Limit the velocity of the physics entity.

    Returns void

Destroy

  • Destroy(): void
  • Destroys this object and removes it from the SharedObjectCache in the GameEngine Also calls all OnDestroyEventHandlers on this SharedObject.

    Returns void

DetachChild

  • DetachChild(child: Phaser.Sprite): Phaser.Sprite
  • Removes the given child from this object's children. Will silently fail if the object is not a child of this entity.

    Parameters

    • child: Phaser.Sprite

      Child to remove.

    Returns Phaser.Sprite

DisableBody

  • DisableBody(): void
  • Disables the body of this physics entity and removes all constraints to this entity.

    Returns void

DisableCircleCollision

  • DisableCircleCollision(collisionGroup: string): void
  • Disable circle collision on this instance.

    Parameters

    • collisionGroup: string

      Collision group to stay in.

    Returns void

EnableBody

  • Creates a P2JS body for this entity.

    Parameters

    Returns void

EnableChildren

  • EnableChildren(mode: PhysicsMode, lockConstraint: boolean): void
  • Creates a P2JS body for all the children of this entity.

    Parameters

    • mode: PhysicsMode

      Physics mode of the child.

    • lockConstraint: boolean

      Creates a constraint with the childs body and that of this entity if set to true.

    Returns void

EnableCircleCollision

  • EnableCircleCollision(radius: number, collisionGroup: string): void
  • Enables circle collision on this instance.

    Parameters

    • radius: number

      Radius of circle collision.

    • collisionGroup: string

      Collision group to stay in.

    Returns void

Equals

  • Returns if the id of the given SharedObjects matches that of this SharedObject.

    Parameters

    • other: SharedObject

      SharedObject of whom's id to compare to.

    Returns boolean

HasTag

  • HasTag(tag: string): boolean
  • Returns if the given tag is present on this SharedObject.

    Parameters

    • tag: string

      Tag to search for.

    Returns boolean

IndexDependencies

  • Add requests to load sprite or spritesheets used for this entity on startup.

    Parameters

    Returns void

OnCollision

  • A on collision handler. Currently only works with Circle Collision!

    Parameters

    • object: PhysicsEntity

      Object that this instance collides with.

    • group: string

      Group that this instance collides with.

    Returns void

OnStart

  • OnStart(): void
  • Called by the game state in the create() method. Assets requested in the IndexDependencies method are loaded at this point.

    Returns void

OnUpdate

  • OnUpdate(): void
  • Returns void

RemoveTag

  • RemoveTag(tag: string): void
  • Remove a tag from this SharedObject. Will silently fail if tag is not present on this SharedObject.

    Parameters

    • tag: string

      Tagg to remove.

    Returns void

Private SetPhysicsMode

  • SetPhysicsMode(body: Phaser.Physics.P2.Body, mode: PhysicsMode): void
  • Switches the phyics mode of the phycis entity.

    Parameters

    • body: Phaser.Physics.P2.Body

      The body to switch the physics mode on.

    • mode: PhysicsMode

      The new physics mode of the body.

    Returns void

Static AddLocalStorageListedItem

  • AddLocalStorageListedItem(key: string, value: any): void
  • Add a value in the list with the given key in the local storage.

    Parameters

    • key: string

      Key of the list in the localStorage.

    • value: any

      Value to add to the list, will be serialized as a string.

    Returns void

Static AddLocalStorageListedItemEntry

  • AddLocalStorageListedItemEntry(key: string): void
  • Creates a emtpy string array and stores it into the LocalStorage.

    Parameters

    • key: string

      Key of the list in the localStorage.

    Returns void

Static GetLocalStorageItem

  • GetLocalStorageItem(key: string): any
  • Returns the value of a localy stored item.

    Parameters

    • key: string

      Key of the item in the LocalStorage.

    Returns any

Static GetLocalStorageListedItem

  • GetLocalStorageListedItem(key: string): string[]
  • Returns an item from the LocalStorage as an array of strings.

    Parameters

    • key: string

      Key of the list in the localStorage.

    Returns string[]

Static HasLocalStorageItem

  • HasLocalStorageItem(key: string): boolean
  • Returns whether an item with the given key is present in the LocalStorage.

    Parameters

    • key: string

      Key of the item in the LocalStorage.

    Returns boolean

Static RemoveLocalStorageItem

  • RemoveLocalStorageItem(key: string): void
  • Removes an item from the LocalStorage.

    Parameters

    • key: string

      Key of the item in the LocalStorage.

    Returns void

Static RemoveLocalStorageListedItem

  • RemoveLocalStorageListedItem(key: string, value: string, stopAtFirstEntry?: boolean): void
  • Removes an item from an array in the LocalStorage.

    Parameters

    • key: string

      Key of the list in the LocalStorage.

    • value: string

      Value to remove from the list.

    • Default value stopAtFirstEntry: boolean = false

      When true, will stop after finding a matching value. Will enumerate through the entire array and delete any matching value otherwise.

    Returns void

Static SetLocalStorageItem

  • SetLocalStorageItem(key: string, value: any): void
  • Add or set a value in the local storage. Will silently fail if LocalStorage is not supported by the browser.

    Parameters

    • key: string

      Key of the item in the LocalStorage.

    • value: any

      Value to store, will be serialized as a string.

    Returns void

Generated using TypeDoc