PIXI.draggable icon indicating copy to clipboard operation
PIXI.draggable copied to clipboard

containment must be direct parent of draggables

Open FlorianLudwig opened this issue 9 years ago • 3 comments

for PIXI.draggable to work all draggable elements must direct children of the containment.

Would be great if it would be more flexible

FlorianLudwig avatar Apr 01 '15 16:04 FlorianLudwig

It should be possible to define a hitArea for that instead of using a Sprite/Object as containment. If there already is a hitArea defined then you could use:

containment: object.hitArea

if not:

containment: new PIXI.Rectangle(x,y,width,height)

If that doesn't work then I'll have to look at it again.

SebastianNette avatar Apr 03 '15 13:04 SebastianNette

shot

As an example, in onDragMove only the width and height of the containment are considered, not the x and y values, so the restriction is always from 0 to containment.width/height in the local space of the dragged element.

FabianElsmer avatar Apr 07 '15 09:04 FabianElsmer

I did the following to fix the issue FabianElsmer is describing. This also makes the containment take any anchor point set on the object (Sprite) into account:

// x bounds
if(options.axis !== 'y')
{
  var anchorXPixelOffset = (item.anchor) ? (item.width * item.anchor.x) : 0;
  var upperXBound = containment.width + containment.x - (item.width - anchorXPixelOffset);
  var lowerXBound = containment.x + anchorXPixelOffset;
    if (x < lowerXBound)
    {
      x = lowerXBound;
    }
    else if (x > upperXBound)
    {
      x = upperXBound;
    }
}

// y bounds
if(options.axis !== 'x')
{
  var anchorYPixelOffset = (item.anchor) ? (item.height * item.anchor.y) : 0;
  var upperYBound = containment.height + containment.y - (item.height - anchorYPixelOffset);
  var lowerYBound = containment.y + anchorYPixelOffset;
    if (y < lowerYBound)
    {
      y = lowerYBound;
    }
    else if (y > upperYBound)
    {
      y = upperYBound;
    }
}

torbenrohde avatar Apr 28 '15 17:04 torbenrohde