Ember

sc_snap

Aug 1st, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Snaps the X/Y values accordingly to a specified isometric grid
  2. //Automatically rounds X/Y values
  3. //arg0 - X value to be snapped to
  4. //arg1 - Y value to be snapped to
  5. //arg2 - X snapping factor
  6. //arg3 - Y snapping factor
  7. //returns nothing
  8.  
  9. //Example
  10. //sc_grid_snap(x,y,32,16);
  11. //That code snaps the object to a 32x16 isometric grid
  12. //The room grid can be used to "pre-test" a grid when set to "Isometric"
  13.  
  14. var yy, check;
  15. yy = argument1;
  16. x = sc_round(argument0,argument2/2);
  17. y = sc_round(argument1,argument3);
  18. check = sc_round(x,argument2);
  19.  
  20. if (check != x)
  21. {
  22.     if point_direction(x,y,x,yy) = 90
  23.     {
  24.         y -= argument3/2;
  25.     }
  26.     else
  27.     {
  28.         y += argument3/2;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment