So I've been fiddling with pygame a tad, and have noticed that animated .gifs do not work, for obvious reasons. I was wondering what the work around this would be. Redrawing and re-flipping the surface is too ugly and affects more than just the image in mind. What would be a more elegant solution to this?
Thanks in advance.
Blinking animation in Pygame
Page 1 of 14 Replies - 876 Views - Last Post: 04 August 2011 - 01:32 PM
Replies To: Blinking animation in Pygame
#2
Re: Blinking animation in Pygame
Posted 01 August 2011 - 06:50 PM
So, are you saying that simply cycling between your image and a transparent image is not an option?
#3
Re: Blinking animation in Pygame
Posted 01 August 2011 - 08:50 PM
atraub, on 01 August 2011 - 06:50 PM, said:
So, are you saying that simply cycling between your image and a transparent image is not an option?
Well, it is, but I keep getting issues with proper timing between blinks. It's inconsistent and does not follow the specific pattern I want.
import pygame, sys
#Initiate pygame
pygame.init()
clock = pygame.time.Clock()
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
#Set up main menu window
window = pygame.display.set_mode((800, 800))
pygame.display.set_caption("Test")
window.fill(BLACK)
title = pygame.image.load('title.bmp')
start = pygame.image.load('enter.bmp')
blank = pygame.image.load('blank.bmp')
window.blit(title, (100, 200))
pygame.display.flip()
#Main menu loop
play = True
menu = True
while menu == True:
clock.tick(10)
#Blink image
window.blit(start, (300, 450))
pygame.display.flip()
window.blit(blank, (300, 450))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
play = False
menu = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
play = False
menu = False
if event.key == pygame.K_RETURN:
menu = False
#4
Re: Blinking animation in Pygame
Posted 02 August 2011 - 06:40 AM
just for giggles, try changing your framerate to 40 (ie clock.tick) 10 milliseconds seems awfully fast, it could be that it's inconsistent because your machine has trouble keeping up.
#5
Re: Blinking animation in Pygame
Posted 04 August 2011 - 01:32 PM
You'll want to perform only one flip per cycle:
With your original code, successive calls to flip() were occasionally occurring before you hardware could refresh the screen, giving you choppy visuals. In practice, you will want to perform all bliting before calling flip() in order to avoid this issue.
...
show_image = False
while menu == True:
clock.tick(10)
#Blink image
if show_image:
window.blit(start, (300, 450))
show_image = False
else:
window.blit(blank, (300, 450))
show_image = True
pygame.display.flip()
...
With your original code, successive calls to flip() were occasionally occurring before you hardware could refresh the screen, giving you choppy visuals. In practice, you will want to perform all bliting before calling flip() in order to avoid this issue.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|