Group
The class Group need for storing sprites
Constructors
Group
<T extends Sprite> ()
Creates a new instance of the sprite group
Properties
sprites
:number
get
Gets all sprites of the group
useCollisionHashmap
:number
get
Uses hashmap algorithm for collide operations
useSpriteCollideRect
:number
get
Uses a sprite collider instead sprite rect for collide operations
Methods
add
(sprite: T) ⇨ void
Adds a sprite to the group
remove
(sprite: T) ⇨ void
Removes a sprite from the group
has
(sprite: T) ⇨ boolean
Checks for existing a sprite in the group
find
(predicate: (sprite: T) ⇨ boolean) ⇨ T | undefined
Finds a sprite in the group
collidePoint
(point: TPoint, callback: (sprite: T) ⇨ void) ⇨ void
Checks collide any sprite a point in the group
collideSprite
<R extends Sprite> (sprite: R, callback: (sprite: T) ⇨ void) ⇨ void
Checks collide a sprite any sprite in the group
Example:
const enemies = new Group<Enemy>()
const hero = new Hero()
enemies.collideSprite(hero, enemy => {
// an enemy is colliding the hero
})
collideGroup
<R extends Sprite> (group: Group<R>, callback: (sprite1: T, sprite2: R) ⇨ void) ⇨ void
Checks collide a sprite group any sprite in the group
Example:
const balls = new Group<Ball>()
const bricks = new Group<Brick>()
balls.collideGroup(bricks, (ball, brick) => {
// a ball is colliding a brick
})
outsideRect
(rect: TRect, callback: (sprite: T) ⇨ void) ⇨ void
Checks any sprite in the group is outside of the rectangle
draw
()
Draws all sprites in the group
protected update
()
The update method calls before the draw method in children classes