[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Re: Paralax snow flaks: Some tipps for enhancing the performance?



Thank you! Now the Dirty Rectangles Methode works...
But i must say, that the performance is lower than in the normal one

Windowed I get 57 without Dirty Rectangles, in Fullscreen 15
With the Dirty Rectangles the fps are 37 Windowed and 11 in Fullscreen (with an unexplainable flickering in fullscreen)...

Could anyone test the two Versions and tell me what could cause this unexpected issue.

well, i think i don't want to get stuck in this problem... perhaps i'll write a little game in windowed mode to gain some more experience in Python and Pygame..

Thank you very much... Ludwig

P.S. Here are the two Sourcecodes

#Schnefall mit Dirty Rectangles 0.1

#Imports
import pygame, random, math
from pygame.locals import *

#Konstanten
MAX_FLOCKEN = 100
MAX_FLOCKEN_SPEED = 5
MAX_FLOCKEN_SIZE = 3
SCREEN_HEIGHT = 768
SCREEN_WIDTH = 1024
SIN_FREQUENZ = 2

#Klassendefinitionen
class Flocke:
#Initialisierung jeder neuen Flocke
def __init__(self):
self.speed = random.randint(1,MAX_FLOCKEN_SPEED)
helligkeit = random.randint(20*self.speed,50*self.speed)
self.color = (helligkeit, helligkeit, helligkeit)
self.size = random.randint(1, MAX_FLOCKEN_SIZE)
self.ypos = random.randint(1,SCREEN_HEIGHT)
self.xpos = random.randint(1,SCREEN_WIDTH)
self.angle = random.randint(0,360)

#Methode zum Darstellen der Flocken
def draw(self):
return screen.fill(self.color, (self.xpos, self.ypos, self.size, self.size))

#Eigenschaften einer Flocke updaten
def update(self):
self.ypos = self.ypos + self.speed
self.xpos = self.xpos + (math.sin(self.angle)*5)
self.angle = self.angle + 0.1

if self.angle >= 360:
self.angle=0

if self.ypos > SCREEN_HEIGHT:
self.ypos = 0



#Standardinitialisierungen
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), HWSURFACE|DOUBLEBUF|FULLSCREEN)
pygame.display.set_caption('Paralaxer Schneefall')
pygame.mouse.set_visible(0)

#Hintergrund erschaffen
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0,0,0))

#Erschaffen der Sterne
flockerl = []
for x in range(0,MAX_FLOCKEN):
flockerl.append(Flocke())

#Dirty Rectangles
dirty = []

#Main Loop
def main():

global dirty
frames=0
ticks = pygame.time.get_ticks()

while 1:

for i in dirty:
screen.blit(background,i,i)
old_dirty = dirty
dirty = []

for jede_flocke in flockerl:
jede_flocke.update()
dirty.append(jede_flocke.draw())

pygame.display.update(old_dirty + dirty)
pygame.display.flip()

frames=frames+1
keyinput = pygame.key.get_pressed ()
if keyinput [ K_ESCAPE] or pygame.event.peek(QUIT):
break
print "fps: %d" % ((frames*1000)/(pygame.time.get_ticks()-ticks))


if __name__=='__main__':
main()




--------------- and here the one without dirty r. ----------------------------------




#Schnefall 0.1

#Imports
import pygame, random, math
from pygame.locals import *

#Konstanten
MAX_FLOCKEN = 100
MAX_FLOCKEN_SPEED = 5
MAX_FLOCKEN_SIZE = 3
SCREEN_HEIGHT = 400
SCREEN_WIDTH = 400
SIN_FREQUENZ = 2

#Klassendefinitionen
class Flocke:
#Initialisierung jeder neuen Flocke
def __init__(self):
self.speed = random.randint(1,MAX_FLOCKEN_SPEED)
helligkeit = random.randint(20*self.speed,50*self.speed)
self.color = (helligkeit, helligkeit, helligkeit)
self.size = random.randint(1, MAX_FLOCKEN_SIZE)
self.ypos = random.randint(1,SCREEN_HEIGHT)
self.xpos = random.randint(1,SCREEN_WIDTH)
self.angle = random.randint(0,360)

#Methode zum Darstellen der Flocken
def draw(self):
screen.fill(self.color, (self.xpos, self.ypos, self.size, self.size))

#Eigenschaften einer Flocke updaten
def update(self):
self.ypos = self.ypos + self.speed
self.xpos = self.xpos + (math.sin(self.angle)*5)
self.angle = self.angle + 0.1

if self.angle >= 360:
self.angle=0

if self.ypos > SCREEN_HEIGHT:
self.ypos = 0



#Standardinitialisierungen
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), HWSURFACE|DOUBLEBUF)
pygame.display.set_caption('Paralaxer Schneefall')
pygame.mouse.set_visible(0)

#Hintergrund erschaffen
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0,0,0))

#Erschaffen der Sterne
flockerl = []
for x in range(0,MAX_FLOCKEN):
flockerl.append(Flocke())


#Main Loop
def main():
frames=0
ticks = pygame.time.get_ticks()

while 1:
screen.blit(background, (0,0))

for jede_flocke in flockerl:
jede_flocke.update()
jede_flocke.draw()

pygame.display.flip()

frames=frames+1
keyinput = pygame.key.get_pressed ()
if keyinput [ K_ESCAPE] or pygame.event.peek(QUIT):
break
print "fps: %d" % ((frames*1000)/(pygame.time.get_ticks()-ticks))


if __name__=='__main__':
main()






Am Dienstag, 04.05.04, um 16:27 Uhr (Europe/Berlin) schrieb Pete Shinners:

that's probably my fault. here is the code that i should have written.