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

SOLVED Problem with door animation. Please help!

Alicja

Member
Hello! :)


I have problem with door.
I want to make a door that opens when I touch a button
and they close when I stop touching that button.

The door opens and the animation stops when it is open. If I move away from the button they have to close and close, but when it comes to sprite number 0 (when door is close) where the animation is to stop, it does not stop and continues forever. When I enter the room, the animation automatically turns on despite the image_speed = 0;.

In sprite spr_door_open_close I set speed to 4 Frames per second.
In sprite spr_mask_button I set speed to 0 Frames per second.

There is my code:
obj_player
CREATE
GML:
obj_button.press = 0;
STEP
GML:
if place_meeting(x,y+1,obj_button) //On button
    {
        obj_button.press = 1;
    }

if !place_meeting(x,y+1,obj_button) //Off button
    {
        obj_button.press = 0;
    }
obj_button
CREATE
GML:
image_speed = 0;
obj_door_open_close
CREATE
GML:
image_speed = 0;
obj_button.press = 0;
STEP
GML:
if image_index = 0 && obj_button.press = 1
{
    image_speed = 0.5; //Open door animation if panel is touch
}

if image_index = 5 && obj_button.press = 0
{
    image_speed = -0.5; //Reverse door animation if panel is not touch
}
ANIMATION END
GML:
if image_index = 5 && obj_button.press = 1
{
    image_speed = 0; //Stop animation
    image_index = 5;
}

if image_index = 0 && obj_button.press = 0
{
    image_speed = 0; //Stop animation
    image_index = 0;
}
 
Last edited:

Nidoking

Member
It looks like whenever the Animation End event sets image_speed to 0, the conditions are such that the Step event will set the image_speed to something else immediately.
 

Alicja

Member
It looks like whenever the Animation End event sets image_speed to 0, the conditions are such that the Step event will set the image_speed to something else immediately.
Exactly. I have been sitting for 5 hours on this problem. :/ And still nothing! Grrrr...
 
Last edited:

Pixel-Team

Master of Pixel-Fu
Why are you checking if the door is NOT on frame zero as a condition to open it? Shouldn't you be checking if it IS on frame 0?
 

Nidoking

Member
Exactly. I have been sitting for 5 hours on this problem. :/ And still nothing! Grrrr...
Instead of sitting on the problem, I would recommend fixing it. You know what the problem is. Your conditions are insufficient to tell the instance what you want it to do. For a piece of stateful information (such as whether the door should be open or closed, i.e. an open STATE or a closed STATE), don't use the graphics to store that information. Use a variable to track the state and use the state to determine what the graphics should do.

Ah, you've edited the post, and now you're just redundantly setting the image_index in the Animation End event. That's a code smell indicating that you don't actually understand what you're doing. Get yourself a rubber duck, and explain what you've done, line by line, to the duck. Explain why you feel you need each line, what it does, and what the state of everything is at each point as you go. This is the best learning tool you will ever have.
 

Gamebot

Member
I would simply put pressed = false into your create button code itself. Your writing the same code several times in different objects EXCEPT the one that needs it. Personally this would confuse me.

For collision I would check for the player on the button in the button's code. Then simply set pressed to true if colliding false if not. Then you can check if true/false in step. DONT copy and paste but I would probably do something closer to this.

BUTTON STEP:

GML:
if ( pressed ) {
  image_index = 0;              // Set button to down
  if ( obj_door.image_speed <= 0 ) { obj_door.image_speed = .5; }
}
else {
image_index = 1;             // Set button to up
if ( obj_door.image_speed > 0) { image_speed = -.5 }
}
DOOR END ANIMATION
GML:
image_speed = 0;
 

Alicja

Member
I would simply put pressed = false into your create button code itself. Your writing the same code several times in different objects EXCEPT the one that needs it. Personally this would confuse me.

For collision I would check for the player on the button in the button's code. Then simply set pressed to true if colliding false if not. Then you can check if true/false in step. DONT copy and paste but I would probably do something closer to this.

BUTTON STEP:

GML:
if ( pressed ) {
  image_index = 0;              // Set button to down
  if ( obj_door.image_speed <= 0 ) { obj_door.image_speed = .5; }
}
else {
image_index = 1;             // Set button to up
if ( obj_door.image_speed > 0) { image_speed = -.5 }
}
DOOR END ANIMATION
GML:
image_speed = 0;
Thanks, but I make this. Sorry I dont put solved in post.
 
Top