Created
March 15, 2013 18:41
-
-
Save alonecuzzo/5172038 to your computer and use it in GitHub Desktop.
Here's how they create a hitArea/hitRadius in the /assets/SpaceRock.js file in the examples folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p.hitPoint = function (tX, tY) { | |
return this.hitRadius(tX, tY, 0); | |
} | |
p.hitRadius = function (tX, tY, tHit) { | |
//early returns speed it up | |
if (tX - tHit > this.x + this.hit) { | |
return; | |
} | |
if (tX + tHit < this.x - this.hit) { | |
return; | |
} | |
if (tY - tHit > this.y + this.hit) { | |
return; | |
} | |
if (tY + tHit < this.y - this.hit) { | |
return; | |
} | |
//now do the circle distance test | |
return this.hit + tHit > Math.sqrt(Math.pow(Math.abs(this.x - tX), 2) + Math.pow(Math.abs(this.y - tY), 2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment