cassidy
cassidy

Reputation: 21

EaselJS Drag-Drop: Get Grabbing Position

I'd like to drag-drop a container element with easeljs. By default event.stageX/stageY refers to the center of the shape or container. That means that large elements are centered at mouse position, doesn't matter, whether I grab them at the top-left or bottom-right corner.

I'd like to have the element bound to the exact mouse position.

Sorry for my bad English, it's not my mother tongue.

Upvotes: 1

Views: 2169

Answers (1)

Wenceslao Negrete
Wenceslao Negrete

Reputation: 556

Maybe it's too late but hope this helps.

container.on('mousedown', function(e){
        var posX = e.stageX;
        var posY = e.stageY;
        this.offset = {x: this.x - posX, y: this.y - posY};
}
container.on('pressmove', function(e){
    var posX = e.stageX;
    var posY = e.stageY;
    this.x = posX + this.offset.x;
    this.y = posY + this.offset.y;
}

Upvotes: 4

Related Questions