1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | var SnailBait = function () { ... didCollide: function (sprite, // runner otherSprite, // candidate for collision context) { // for context.isPointInPath() var MARGIN_TOP = 10, MARGIN_LEFT = 10, MARGIN_RIGHT = 10, MARGIN_BOTTOM = 0, left = sprite.left + sprite.offset + MARGIN_LEFT, right = sprite.left + sprite.offset + sprite.width - MARGIN_RIGHT, top = sprite.top + MARGIN_TOP, bottom = sprite.top + sprite.height - MARGIN_BOTTOM, centerX = left + sprite.width/2, centerY = sprite.top + sprite.height/2; ... }, ... }; |
1 2 3 4 5 6 7 8 | this.isCandidateForCollision: function (sprite, otherSprite) { return sprite !== otherSprite && sprite.visible && otherSprite.visible && !sprite.exploding && !otherSprite.exploding && otherSprite.left - otherSprite.offset < sprite.left + sprite.width; }, |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |