Collisions can be detected with the fabric.js 'intersectsWithObject' function. Consider their 'intersection' example:
collision detection fabrics js
-
08-07-2023 - |
Domanda
I am using fabric js, i use the following function to put an image on canvas, when i click on canvas an image is put on that location, i want to know if there is way that i can check weather there is something already present at location where i am clicking especially if there is another image or not
document.getElementById("door").onclick = function () {
canvas.on('mouse:down', function (o) {
fabric.Image.fromURL('http://localhost:60099/Images/door.png', function (img) {
var pointer = canvas.getPointer(o.e);
logo = img.set({ left: pointer.x , top: pointer.y })
canvas.add(logo);
canvas.item(objC).lockMovementY = true;
canvas.item(objC).lockMovementX = true;
canvas.renderAll();
});
});
}
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow