Advertisement
Guest User

Untitled

a guest
Dec 25th, 2018
1,115
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.  
  39. //---------------------DRAW EVENT
  40. if(hInput != 0 or vInput != 0){     //Are we moving?
  41.     y_frame = dir/45;
  42.     //INCREMENT FRAME FOR ANIMATION
  43.     x_frame += anim_speed/room_speed;
  44.     if(x_frame >= anim_length) x_frame = 0;
  45. } else {
  46.     x_frame = 0.9;      //If not moving, freeze the animation on the first frame
  47. }
  48.  
  49. var xx = x-x_offset;    //Calculate where to draw sprite, depending on "origin" placement
  50. var yy = y-y_offset;
  51.  
  52. //DRAW SPRITE PART
  53. draw_sprite_part_ext(
  54.     spr_spritesheet,
  55.     0,
  56.     floor(x_frame)*frame_size,
  57.     y_frame*frame_size,
  58.     frame_size,
  59.     frame_size,
  60.     xx,
  61.     yy,
  62.     image_xscale,image_yscale,image_blend,image_alpha
  63. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement