Advertisement
Guest User

Untitled

a guest
Dec 25th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. NOTE!!
  4.  
  5. This system will only work for a spritesheet in a certain format. See "spr_spritesheet" here: https://1drv.ms/f/s!Amc0xkhdlKo2hToKw1756LYgatf_
  6. Each animation (ie. the each direction) is placed in a new row, in a SPECIFIC order: starting with right (0 degrees), and increasing by 45 degrees (up right, up, up left, left, down left, down, down right).
  7.  
  8. */
  9.  
  10. //---------------------CREATE EVENT
  11. spd = .5;           //movement speed
  12.  
  13.                     //The x_offset and y_offset represent where you would place the ORIGIN if we were not using a spritesheet.
  14. x_offset = 8;       //how many pixels over is it from the LEFT?
  15. y_offset = 16;      //how many pixels over is it from the TOP?
  16. frame_size = 17;    //in your spritesheet, what is the size of each frame? (make sure frames are all evenly spaced)
  17. anim_length = 4;    //how many sprites are in a ROW? (eg. how long is the animation)
  18. anim_speed = 4;     //the speed of your animation in frames per second
  19.  
  20. //For initialising. Leave these!
  21. x_frame = 0;
  22. y_frame = 0;
  23. dir = 0;
  24.  
  25. //---------------------STEP EVENT - NOTE: this is unchanged from the first video
  26. //Movement
  27. hInput = keyboard_check(vk_right) - keyboard_check(vk_left);
  28. vInput = keyboard_check(vk_down) - keyboard_check(vk_up);
  29.  
  30. if(hInput != 0 or vInput != 0){
  31.     dir = point_direction(0,0,hInput,vInput);
  32.     moveX = lengthdir_x(spd, dir);
  33.     moveY = lengthdir_y(spd, dir);
  34.  
  35.     x += moveX;
  36.     y += moveY;
  37.    
  38. } else {
  39.     image_index = 0;
  40. }
  41.  
  42. //---------------------
  43. if(hInput != 0 or vInput != 0){
  44.     y_frame = dir/45;
  45.     //INCREMENT FRAME FOR ANIMATION
  46.     x_frame += anim_speed/room_speed;
  47.     if(x_frame >= anim_length) x_frame = 0;
  48. } else {
  49.     x_frame = 0.9;
  50. }
  51.  
  52. var xx = x-x_offset;
  53. var yy = y-y_offset;
  54.  
  55. //DRAW SPRITE PART
  56. draw_sprite_part_ext(
  57.     spr_spritesheet,
  58.     0,
  59.     floor(x_frame)*frame_size,
  60.     y_frame*frame_size,
  61.     frame_size,
  62.     frame_size,
  63.     xx,
  64.     yy,
  65.     image_xscale,image_yscale,image_blend,image_alpha
  66. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement