Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- NOTE!!
- This system will only work for a spritesheet in a certain format. See "spr_spritesheet" here: https://1drv.ms/f/s!Amc0xkhdlKo2hToKw1756LYgatf_
- 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).
- */
- //---------------------CREATE EVENT
- spd = .5; //movement speed
- //The x_offset and y_offset represent where you would place the ORIGIN if we were not using a spritesheet.
- x_offset = 8; //how many pixels over is it from the LEFT?
- y_offset = 16; //how many pixels over is it from the TOP?
- frame_size = 17; //in your spritesheet, what is the size of each frame? (make sure frames are all evenly spaced)
- anim_length = 4; //how many sprites are in a ROW? (eg. how long is the animation)
- anim_speed = 4; //the speed of your animation in frames per second
- //For initialising. Leave these!
- x_frame = 0;
- y_frame = 0;
- dir = 0;
- //---------------------STEP EVENT - NOTE: this is unchanged from the first video
- //Movement
- hInput = keyboard_check(vk_right) - keyboard_check(vk_left);
- vInput = keyboard_check(vk_down) - keyboard_check(vk_up);
- if(hInput != 0 or vInput != 0){
- dir = point_direction(0,0,hInput,vInput);
- moveX = lengthdir_x(spd, dir);
- moveY = lengthdir_y(spd, dir);
- x += moveX;
- y += moveY;
- }
- //---------------------DRAW EVENT
- if(hInput != 0 or vInput != 0){ //Are we moving?
- y_frame = dir/45;
- //INCREMENT FRAME FOR ANIMATION
- x_frame += anim_speed/room_speed;
- if(x_frame >= anim_length) x_frame = 0;
- } else {
- x_frame = 0.9; //If not moving, freeze the animation on the first frame
- }
- var xx = x-x_offset; //Calculate where to draw sprite, depending on "origin" placement
- var yy = y-y_offset;
- //DRAW SPRITE PART
- draw_sprite_part_ext(
- spr_spritesheet,
- 0,
- floor(x_frame)*frame_size,
- y_frame*frame_size,
- frame_size,
- frame_size,
- xx,
- yy,
- image_xscale,image_yscale,image_blend,image_alpha
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement