• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Draw Sprite Code causing Collision code issues

M

Malawi

Guest
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```````
 

TheouAegis

Member
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.
 
M

Malawi

Guest
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.
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.
 

TheouAegis

Member
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.
 
Top