Hello,
I want to drag and move around a GameObject just in an restricted Area. How to do that?
So far:
var canDrag = this.matter.world.nextGroup();
this.matter.add.pointerConstraint({
label: 'Pointer Constraint',
pointA: { x: 10, y: 400 },
pointB: { x: 200, y: 550 },
damping: 0,
length: 1,
stiffness: 1,
angularStiffness: 1,
collisionFilter: {
category: 0x0001,
mask: 0xFFFFFFFF,
group: 'canDrag'
}
});
var player = this.matter.add.sprite(startX,startY, 'player', null, { chamfer: 16 }).setBounce(0.9).setCollisionGroup(canDrag);;
player.setData('name', 'player');
player.setIgnoreGravity(true);
player.setInteractive({draggable: true});
So … then the clickHandler schould be on the world:
this.matter.world.on('drag', clickHandler);
function clickHandler (pointer,dragX,dragY) {
player.x=pointer.x;
player.y=pointer.y;
}
So the funny thing is, add pointerConstrains enables drag for all objects!??? I am confused I think I am completely on the wrong path…
So just how to have an gameObject drag in just an Area? (Shape would be nice!)
I try
player.on(‘drag’,clickHandler)
and did there an if for pointer but this seems to ugly too me.(origin-Obj,pointer … )
The on drag on matter.word should emit a custom Event to GameObject when pointerConstrains is what I am searching for moving a gameObject in just and defined space.
Thanks for help,
Tom
PS: can’t find any Examples … just reference/source