
I wanted to have my tokens face the direction they are moving in so I came up with this: on("change:graphic", function(obj, prev)
{
if(obj && prev && (obj.get('top') !== prev.top || obj.get('left') !== prev.left) )
{
if (prev.top > obj.get('top'))
{
// Going North
obj.set('rotation', 180);
} else if (prev.top < obj.get('top')) {
// Going South
obj.set('rotation',0);
} else if (prev.left > obj.get('left')) {
// Going West
obj.set('rotation', 90);
} else if (prev.left < obj.get('left')) {
// Going East
obj.set('rotation', 270);
}
}
});
I'm going to expand on it for Northeast/Northwest/Southeast/Southwest calculations but it's too late and my brain can't take it right now. Thought I'd share this little snippet for anyone who might be interested in having this functionality.