setDraggable not working

Hello, I am trying to make a draggable image (called ‘icon’).

this.input.setDraggable(icon);

yields error ‘Cannot set property ‘draggable’ of null’. (InputPlugin.js error.) It entails that icon.input is null for some reason. Can’t understand why, when compared to this example, where it is not null.

The only difference I can think of is the fact that my image is declared and being set to draggable inside a function of a class extending Scene. (Using ES6 with webpack, if it matters.)

You might miss gameObject.setInteractive({ draggable: true }).

gameObject.setInteractive({ draggable: true });
scene.input.setDraggable(gameObject);

Reference

1 Like

This works!
I didn’t know I needed to insert { draggable: true } as the setInteractive() method parameter. In the example I linked above, the method works without any parameters.
Thank you.

what if i have passed the rectangle object in setinteractive instead of passing input config? this scenario happening for container.

You pass the rectangle in the config object as well.

Should be:

gameObject.setInteractive({ draggable: true, hitArea: rectangleObject});
1 Like

I have one more problem: this.input.dragDistanceThreshold = xxx not working, no matter where in the code I put it. Any ideas, please? I am starting to think that dragging doesn’t work well with dynamic scenes…