Guest User

GMS Shadows

a guest
Mar 10th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///draw shadows
  2. //manage surface
  3. if(surface_exists(surf_shadow)){
  4.     surface_set_target(surf_shadow);
  5.     draw_clear_alpha(0, 0);
  6. }else{
  7.     surf_shadow = surface_create(room_width,room_height);
  8.     surface_set_target(surf_shadow);
  9. }
  10.  
  11. //handle every shadow in the room
  12. with(o_5_char_shadow){
  13.     if(parent>-1){
  14.         if(instance_exists(parent)){
  15.             if(parent.visible){
  16.                 //transformation points
  17.                 var px = parent.x;
  18.                 var py = parent.y;
  19.                 var w = sprite_get_width(parent.sprite_index)*global.zoom;
  20.                 var h = parent.footground*global.zoom;
  21.                 var wd = 50; //horizontal iclination
  22.                 var hd = h/1.5; //vertical inclination
  23.                 var xoff = (sprite_get_xoffset(parent.sprite_index)+1)*global.zoom;
  24.                 var yoff = parent.sprite_height-(parent.footground+1)*global.zoom;
  25.                 //check if there's the necessity of duplicating a new sprite
  26.                 if(parent.sprite_index!=last_sprite){
  27.                     //delete previous duplicated sprite
  28.                     if(sp!=-1) sprite_delete(sp);
  29.                     //create new duplicated sprite
  30.                     sp = sprite_duplicate(parent.sprite_index);
  31.                     sprite_collision_mask(sp,false, 1, 0, 0, 0, 0, 1, 0);
  32.                     last_sprite = parent.sprite_index;
  33.                 }
  34.                 sprite_index = sp;
  35.                 //draw skewed sprite
  36.                 draw_sprite_pos(sprite_index,
  37.                                 parent.image_index,
  38.                                 px+wd-xoff,
  39.                                 py+h+hd,
  40.                                 px+w+wd-xoff,
  41.                                 py+h+hd,
  42.                                 px+w-xoff,
  43.                                 py+h-yoff,
  44.                                 px-xoff,
  45.                                 py+h-yoff,
  46.                                 1);
  47.             }
  48.         }else{
  49.             instance_destroy();
  50.         }
  51.     }
  52. }
  53.  
  54. //reset drawing target
  55. surface_reset_target();
  56. //draw the modified shadow sprites with black blending color and 20% alpha
  57. draw_surface_ext(surf_shadow, 0, 0, 1, 1, 0, c_black, 0.1);
Advertisement
Add Comment
Please, Sign In to add comment