Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Group

Groups are used for logically grouping Actors so they can be acted upon in bulk.

obsolete

Use CollisionGroupManager for collision based behavior

Using Groups

Groups can be used to detect collisions across a large number of actors. For example perhaps a large group of "enemy" actors.

const enemyShips = engine.currentScene.createGroup("enemy");
const enemies = [...]; // Large array of enemies;
enemyShips.add(enemies);
const player = new Actor();
engine.currentScene.add(player);
enemyShips.on('precollision', function(ev: CollisionEvent){
  if (e.other === player) {
      //console.log("collision with player!");
  }
});

Hierarchy

Implements

Index

Constructors

constructor

Properties

actions

actions: ActionContext = new ActionContext()

eventDispatcher

eventDispatcher: EventDispatcher

Direct access to the game object event dispatcher.

name

name: string

scene

scene: Scene

Methods

add

  • add(actor: Actor): void
  • add(actors: Actor[]): void

contains

  • contains(actor: Actor): boolean

emit

  • emit(topic: string, event: GameEvent<any>): void

getBounds

getMembers

getRandomMember

  • getRandomMember(): Actor

move

  • move(vector: Vector): void
  • move(dx: number, dy: number): void

off

  • off(eventName: string, handler?: function): void
  • Parameters

    • eventName: string
    • Optional handler: function

    Returns void

on

  • on(eventName: string, handler: function): void

once

  • once(eventName: string, handler: function): void
  • Once listens to an event one time, then unsubscribes from that event

    Parameters

    • eventName: string

      The name of the event to subscribe to once

    • handler: function

      The handler of the event that will be auto unsubscribed

    Returns void

remove

  • remove(actor: Actor): void

rotate

  • rotate(angle: number): void
  • Parameters

    • angle: number

    Returns void

Static extend

  • extend(methods: any): any
  • You may wish to extend native Excalibur functionality in vanilla Javascript. Any method on a class inheriting Class may be extended to support additional functionality. In the example below we create a new type called MyActor.

    var MyActor = Actor.extend({
    
       constructor: function() {
          this.newprop = 'something';
          Actor.apply(this, arguments);
       },
    
       update: function(engine, delta) {
          // Implement custom update
          // Call super constructor update
          Actor.prototype.update.call(this, engine, delta);
    
          console.log("Something cool!");
       }
    });
    
    var myActor = new MyActor(100, 100, 100, 100, Color.Azure);

    In TypeScript, you only need to use the extends syntax, you do not need to use this method of extension.

    Parameters

    • methods: any

      A JSON object contain any methods/properties you want to extend

    Returns any