• 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!

Platformer door open and close, mask problem?

G

Goat Mutation

Guest
Interested in methods for doors that close and open when character is close enough to it.
I took a shot at coding one... but it's not working out. My door has 4 frames. 1 closed frame, 2 opening frames, and 1 open frame.

Create Event
Code:
image_index = 0;
image_speed = 0;
open = false;
Step Event
Code:
// reaper close to door and hits spacebar, check if opened or closed and set to opposite
if (distance_to_object(obj_reaper) <= 5) and (keyboard_check_pressed(vk_space)) and (open == false){
    mask_index = spr_nomask;
    open = true;
    
    
} else {
    if (distance_to_object(obj_reaper) <= 5) and (keyboard_check_pressed(vk_space)) and (open == true){
        mask_index = spr_door_wood;
        open = false;
        
    }
}

// Play animation based on open variable
if (open == true) and (image_index = 0) {
    image_speed  = 1;
}

if (open == false) and (image_index = 3) {
    image_speed -= 1;
}

// Animation checking for open variable
if (open == true) and (image_index = 3) {
    image_speed = 0;
}

if (open == false) and (image_index = 0) {
    image_speed = 0;
}
My main problem with using this is for some reason I still get some tiny bits of collision mask appearing where the door started even though I have it changing to a nomask sprite. And unless i'm like touching those strange bits of collision that make me stuck in the air, I am not able to close the door. If anyone could help me out, it would be much appreciated!
 

TheouAegis

Member
What I would do is when image_index equals 3, set sprite_index to -1. This will remove the sprite from the door. In the Draw Event, check if sprite_index equals -1 then use draw_sprite(spr_door_wood,3,x,y) to simply draw the door as "open". That way it will have no collision. Don't even bother with a mask.
 
G

Goat Mutation

Guest
What I would do is when image_index equals 3, set sprite_index to -1. This will remove the sprite from the door. In the Draw Event, check if sprite_index equals -1 then use draw_sprite(spr_door_wood,3,x,y) to simply draw the door as "open". That way it will have no collision. Don't even bother with a mask.
Man I'm such a noob, I tried doing what you said but it still ends up having some random collision box top left corner of my object. Here's what I got..
Step Event
Code:
// reaper close to door and hits spacebar, check if opened or closed and set to opposite
if (distance_to_object(obj_reaper) <= 5) and (keyboard_check_pressed(vk_space)) and (open == false){
    open = true;
    
    
} else {
    if (distance_to_object(obj_reaper) <= 5) and (keyboard_check_pressed(vk_space)) and (open == true){
        open = false;
        
    }
}

// Play animation based on open variable
if (open == true) and (image_index = 0) {
    image_speed  = 1;
}

if (open == false) and (image_index = 3) {
    image_speed -= 1;
}

// Animation checking for open variable
if (open == true) and (image_index = 3) {
    sprite_index = -1;
    image_speed = 0;
}

if (open == false) and (image_index = 0) {
    image_speed = 0;
}
Draw Event
Code:
if (sprite_index == -1){
    draw_sprite(spr_door_wood,3,x,y);
} else {draw_self()}
I don't understand why there is still some discombulated collision box. Is my draw event coded ok?
 

TheouAegis

Member
The Draw is fine.

I've heard someone else say he had issues with spriteless objects still having collisions. Which version of GM are you using?
 
G

Goat Mutation

Guest
The Draw is fine.

I've heard someone else say he had issues with spriteless objects still having collisions. Which version of GM are you using?
Game Maker Pro v1.4.1763

Also, I have obj_solid as a parent so I can collide with the door. Removing it as a child for that did stop the collision issue, but then I have no collision. Hoping I can still make use of the obj_solid collision somehow and not be forced to write out more collision coding just for doors. Don't know if that helps.
 
Last edited by a moderator:

TheouAegis

Member
Then just make a new collision event/code strictly for the door. It won't kill the game, it's just extra ROM memory.
 
Top