سؤال

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();

                });

            });

        }
هل كانت مفيدة؟

المحلول

Collisions can be detected with the fabric.js 'intersectsWithObject' function. Consider their 'intersection' example:

http://fabricjs.com/intersection

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top