Draw Sprite Code causing Collision code issues

Discussion in 'Programming' started by Malawi, Jan 11, 2019.

Tags:
  1. Malawi

    Malawi Member

    Joined:
    Jan 10, 2019
    Posts:
    2
    I am running into an issue where when I added code to draw my players sprite it interfered with the collision code that prevented the sprite from passing through objects and players. The code still runs, however, now the player just passes through other objects.

    My thought is that the issue occurred somewhere around when I added the code to change the sprite based on the direction it is going, but I am not sure.

    Thank you all for taking the time to take a look.

    ```````STEP CODE`````````
    //input variables
    input_left = keyboard_check(vk_left);
    input_right = keyboard_check(vk_right);
    input_up = keyboard_check(vk_up);
    input_down = keyboard_check(vk_down);
    input_walk = keyboard_check(vk_control);
    input_run = keyboard_check(vk_shift);
    //reset move variables
    movex = 0;
    movey = 0;
    //speed control
    if(input_walk or input_run){
    //normal speed must be midpoint between walk and run speed
    spd =abs((input_walk*w_spd) - (input_run*r_spd))
    }
    //intended movement
    movex = (input_right - input_left)*spd;
    if(movex == 0){movey =(input_down - input_up)*spd;}
    //---collision check
    //horizontal
    if(movex != 0){
    if(place_meeting(x+movex, y, obj_collision)){
    repeat (abs(movex)){
    if(!place_meeting(x+sign(movex), y, obj_collision)){x += sign(movex);}
    else {break;}
    }
    movex = 0;
    }
    }
    //vertical
    if(movey != 0){
    if(place_meeting(x, y+movey, obj_collision)){
    repeat (abs(movey)){
    if(!place_meeting(x,y+sign(movey),obj_collision)){y += sign(movey);}
    else {break;}
    }
    movey = 0;
    }
    }
    //apply movement
    x += movex;
    y += movey;



    ```````DRAW SPRITE CODE`````````
    //creating sprites
    var anim_length = 9;
    var frame_size = 64;
    var anim_speed = 12;

    //sprite y-coords: up-8, left-9, down-10, right-11
    //makes sprite change directions
    if(movex < 0) {yframe = 9;}
    else if(movex > 0) {yframe = 11;}
    else if(movey > 0) {yframe = 10;}
    else if(movey < 0) {yframe = 8;}
    else {xframe = 0;}

    draw_sprite_part(darkelf_male_base,0,floor(xframe)*frame_size,yframe*frame_size,frame_size,frame_size,x,y);

    //incremental frames for animation
    if(xframe < anim_length - 1) {xframe += anim_speed/60;}
    else {xframe = 1;}

    ```````CREATE VARIABLES```````
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,544
    Does the player have a sprite or a mask assigned? Without a sprite or a mask assigned to it, it won't perform any collision checks.
     
  3. Malawi

    Malawi Member

    Joined:
    Jan 10, 2019
    Posts:
    2
    I do have a sprite assigned to 'obj_player' and one for 'obj_collision' as well, I also double checked the collision masks to make sure they were covering the entire sprite, which they were.
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,544
    The object properties itself has the sprite set? Do you have any references to sprite_index? Your movement code looks fine to me, Draw code doesn't affect collisions.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice