-1

I have searched for other similiar threads but nothing came up. what i want to be able to is blit a sprite onto the window for lets say 5 seconds (5000 milliseconds) and at when time is up, it unblits it. thank you.

class Flag():

    def Flagrun(self):
        flaggen = str(randint(1,4))
        global milliseconds
        global flagactive
        if flaggen == '1':
            flag_x = 58
            flag_y = 89

        elif flaggen == '2':
            flag_x = 464
            flag_y = 82            

        elif flaggen == '3':
            flag_x = 343
            flag_y = 215

        elif flaggen == '4':
            flag_x = 66
            flag_y = 535

        window.blit(flag, (flag_x,flag_y))
        collisiondet()
        milliseconds += clock.tick_busy_loop(60)
        print(milliseconds)
        flagactive = 'No'
  • 1
    You should post the code in the question rather than posting if needed – techydesigner Oct 24 '16 at 03:46
  • You need to be more descriptive. Will the sprite blit _every_ 5 milliseconds, or will it blit for _only_ five seconds at the beginning of the program? – Christian Dean Oct 24 '16 at 04:16
  • so when this piece of code is called, i want each of the if or elif statements to give flag_x and flag_y their coordinates. dont worry about the game it self, it would be too hard to explain. what i want is the flags to blit every 14000milliseconds with each of them staying on the screen for 4000milliseconds. does this make sense? – Ali mickey Oct 24 '16 at 07:23
  • at start set variable using `current time + 5 second`. Later in your loop compare this variable with `current time` and blit or not. – furas Oct 24 '16 at 08:18
  • I think you are misunderstanding something here. If you want to "unblit" something you just dont blit it next frame. You should be getting 40-60 frames every second or so. – cmd Oct 24 '16 at 21:43
  • i want the image to stay on the screen for 5 seconds. can i do this? – Ali mickey Oct 24 '16 at 22:29
  • Set a variable to the time 5 seconds in the future. Then blit it as long as the current time is less then the variable. – cmd Oct 25 '16 at 19:44

1 Answers1

0

There are many ways you can accomplish what you are trying to accomplish. You cannot just "unblit" an image, you have to draw over it, either by erasing the screen, or redrawing whatever's supposed to be behind it.

Here is a very basic program that displays a red circle every other second, a blue circle every other two seconds, a green circle that displays every other three seconds, and a yellow circle that displays every third second. This makes use of modulo to keep track of when things should be displayed.

import pygame, sys
pygame.init()
screen = pygame.display.set_mode([400,100])
clock = pygame.time.Clock()

timer = 0
fps = 60
while 1:
    clock.tick(fps)
    timer += 1
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    screen.fill([255,255,255])
    if int(timer/fps)%2==0:
        pygame.draw.circle(screen, [255,0,0], [0,0], 50)
    if int(timer/(fps*2))%2==0:
        pygame.draw.circle(screen, [0,0,255], [100,0], 50)
    if int(timer/(fps*3))%2==0:
        pygame.draw.circle(screen, [0,255,0], [200,0], 50)
    if int(timer/fps)%3==0:
        pygame.draw.circle(screen, [255,255,0], [300,0], 50)
    pygame.display.flip()

You should be able to include something similar in your program. If you are confused with how to do this, please contribute your coding so I can put this in context. I haven't been able to test this code (using school computer), but it should work. If you have any additional questions, just leave them in a comment below, and I'll answer them as soon as possible.

Douglas
  • 1,304
  • 10
  • 26