Using modulo to snap an object


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Snap object depending on the snapToSize
  2. // Can be used for window dragging or in games etc.
  3. // if the side of my square in my grid is 250, the snapToSize parameter would be 250.
  4. // If it is 100, the snapToSize parameter would be 100.
  5.  
  6. var snapToSize:int = 5;
  7.  
  8. snapClip_mc.x = mouseX - mouseX % snapToSize;
  9. snapClip_mc.y = mouseY - mouseY % snapToSize;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.