[英]CreateJS Collision Detection
我在設置碰撞檢測時遇到問題。 我已經關注了該論壇和網絡上的一些帖子,但似乎無法使其正常工作。 我正在嘗試使用位於函數中的正方形邊界框方法。
正方形是通過用戶輸入在畫布上移動的形狀,而ImpactSquare是我要用來測試其沖擊力的固定形狀。 我似乎無法弄清楚是什么原因導致其無法正常工作。
//square bounding box
if (impactSquare.x < square.x + square.width &&
impactSquare.x + impactSquare.width > square.x &&
impactSquare.y < square.y + square.height &&
impactSquare.height + impactSquare.y > square.y) {
// collision detected!
//square.graphics.beginFill("#F4F4F4");
console.log("Collision Detected");
} else {
// no collision
//square.graphics.beginFill("#FF0000");
console.log("No Collision");
}
//stage.update();
感謝您提供的幫助!
您可能會遇到問題,因為您要嘗試的是像素完美的hitTest。
在這里,使用它: https : //github.com/olsn/Collision-Detection-for-EaselJS的工作原理很像。
如果相交處為空,那是因為沒有碰撞。
if (intersection !== null) {
// hit
}
干杯,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.