user1136881
user1136881

Reputation: 172

Changing coordinates in event "on modified"

When I move the object. In the event "modified" I check if I didn't move the object outside of the grid. If I did,then I return object to its initial coordinates. It returns right. But when I try to move it again. I can't drag it. It looks like visual coordinates are updated. But some collision coordinates didn't.How to update this interactive layer coordinates?

http://jsfiddle.net/4Ubjk/3/

canvas.on({
      'object:moving': function(e) {
        e.target.opacity = 0.5;
        canvas.renderAll();
      },
      'object:modified': function(e) {
        e.target.opacity = 1;
         //e.target.left = 10;
        var nx = Math.floor((e.target.left - offset)/60);
        var ny = Math.floor((e.target.top - offset)/60);
        if(nx > 4 || nx < 0 || ny > 4 || ny < 0)
        {
          nx = e.target.ix;
          ny = e.target.iy;
        }
        e.target.ix = nx;
        e.target.iy = ny;
        //e.target.set('top', offset + 30+e.target.iy*60);
        //e.target.set('left', offset + 30+e.target.ix*60);

        e.target.set('top', offset + 30+ny*60);
        e.target.set('left', offset + 30+nx*60);
        canvas.renderAll();
      }
    });

Upvotes: 1

Views: 223

Answers (1)

user1136881
user1136881

Reputation: 172

after reading source code, tried next function and it helped.

e.target.setCoords();

Upvotes: 1

Related Questions