Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

4. Building A Game > checkAgainst Property

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 );
}