O'Reilly logo

Building HTML5 Games with ImpactJS by Jesse Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

checkAgainst Property

The .checkAgainst property tells an entity which type property to check for when it collides with another entity. An entity can check for four types during the collision:

ig.Entity.TYPE.NONE
ig.Entity.TYPE.A
ig.Entity.TYPE.B
ig.Entity.TYPE.BOTH

The default value is always set to NONE. When two entities overlap, the .checkAgainst property of one entity is compared with the .type property of the other. If there is a match, the first entity’s check() method is called, and the latter object with which it collided is sent to the method as a parameter. You can customize the check() method to respond to such a collision

This example, which we’ll discuss in greater detail in a moment, shows damage applied after such a collision:

check: function( other ) {
    other.receiveDamage( 10, this );
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required