PIXI.js Drag and drop tutorial

Trooper.life multiplayer 2d shooter

Hello again, this one is a quicky, it's a Sunday and I had myself a beer so... short, simple and useful, here you go

var drag = false;  
createDragAndDropFor(container)

function createDragAndDropFor(target){  
  target.interactive = true;
  target.on("mousedown", function(e){
    drag = target;
  })
  target.on("mouseup", function(e){
    drag = false;
  })
  target.on("mousemove", function(e){
    if(drag){
      drag.position.x += e.data.originalEvent.movementX;
      drag.position.y += e.data.originalEvent.movementY;
    }
  })
}

Cheers!

Proclive d.o.o | Sjedište: Jozefinska cesta 1, 47250 Duga Resa | OIB: 25746491360 | MBS: 4613180 | Temeljni kapital: 20.000,00 kn uplaćen u cijelosti | Član uprave društva: Igor Neuhold, direktor | Proclive d.o.o. za usluge upisano je pri Trgovačkom sudu u Zagrebu - stalna služba u Karlovcu pod poslovnim brojem Tt-16/31137-4 | IBAN: HR85 2340 0091 1108 1612 1, PRIVREDNA BANKA ZAGREB d.d | SWIFT: PBZGHR2X | Terms of Service and Privacy Policy