0
我試圖解鎖我的遊戲。我有一些對象,我做了邊界碰撞。但是現在我被對象之間的碰撞困住了。我在數組中循環了對象,但它停在最後一個對象上。我每次移動選定對象時如何對每個對象進行碰撞檢查? Full code here:http://foxfcb.sweb.cz/我是編程新手,所以請耐心等待。畫布中的多次碰撞
canvas.addEventListener('mousemove', function (e) {
...
var shapes = myState.shapes;
var l = shapes.length;
for (var i = 0; i < l; i++) {
var shape = myState.shapes[i];
var selection = myState.selection;
// collision between objects
if (selection.x < (shape.x + shape.w) && (selection.x + selection.w) > shape.x &&
selection.y < (shape.y + shape.h) && (selection.y + selection.h) > shape.y) {
myState.valid = true; //stop
}
// boundaries collision
else if (myState.selection.x < 0 || myState.selection.y < 0 || myState.selection.x + myState.selection.w > 600 || myState.selection.y + myState.selection.h > 600) {
myState.valid = true; //stop
}
else {
myState.valid = false; //moving
}
}
}
對不起,我沒有寫信給你。這是休息的好主意,但還有一個錯誤。數組中包含的對象實際上是在移動。因此它在開始時通過條件並停止移動。我需要提取對象,我實際上是從數組中移出。但我認爲我可以做到。非常感謝。真正appriciate你的幫助。 –
好的,我爲我的陣列做了條件,它工作正常! :) if(shapes [i]!== myState.selection){ ... } –