Python Forum
cant make a door automatically close a few seconds after i open it in pygame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cant make a door automatically close a few seconds after i open it in pygame
#1
whenever i make a wait function after the door is opened it just freezes the game instead of just freezing the door.
    def door_open(self):
        if self.flag == 'door_h':
            self.y -= 3
            if abs(self.y - self.door_prev_pos) > TILE:
                self.door_open_trigger = False
                self.door_close_trigger = True

        elif self.flag == 'door_v':
            self.x -= 3
            if abs(self.x - self.door_prev_pos) > TILE:
                self.door_open_trigger = False
                pygame.time.wait(2000)
                self.door_close_trigger = True
Reply
#2
I believe the reason is because pygame.time.wait() is not meant to work on an object itself in the way you are intending. As described in the documentation this method is actually intended to stop or 'freeze' the process overall which is the main application or the program itself for the allotted time you specify in milliseconds, which you have put 2,000. So, at this point in the program you are saying that you want to pause the entire process for 2000 milliseconds or 2 seconds. Which it should be fairly consistent to your arguments each time unless there are any latency issues it should be freezing for around 2 seconds and continuing.

I am not sure if I am correct, I personally don't use PyGame as much but I aspire to do so in the future and it is sorta what I spend so much time scripting and preparing for. I may be completely wrong but I think what you are looking for is something along the lines of the event queue using pygame.event() read the documentation about handling events in python. You may be able to create key press event, or an event timer or something that allows the doors to stay in the relevant position (open) during the timer or event period. This is just a long shot idea but I hope it helps you get to the overall answer!
Reply
#3
This is basically the same as the last question you asked. You need to track the passage of time with either get_ticks() or time.time(). sleep() and wait() are not suited to your needs.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] PyGame does not close when I press the close button Midnight_Sparkle3344 9 24,997 Dec-16-2022, 03:55 PM
Last Post: d3sh19th
  How to make enemy chase me in pygame? Jan_97 3 4,380 Nov-23-2021, 05:08 PM
Last Post: Jan_97
  How to make an image move in relation to another in PYGAME CompleteNewb 1 2,303 Nov-10-2021, 03:38 PM
Last Post: metulburr
  Trying to make boundries for the pygame bluewing101 2 2,035 Mar-23-2020, 01:35 AM
Last Post: Windspar
  open cv ->pygame: turn image into location Gamedeveloper 1 2,059 Jan-20-2020, 05:00 PM
Last Post: michael1789
  How can I make music with python/pygame? xBlackHeartx 12 7,191 Oct-15-2019, 08:00 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020