在我之前的question上,我遇到了精灵问题。所以我决定在绘制它们之前使用clear方法。它似乎有效,但是当精灵们到达屏幕的底部时,也就是当它们应该回到顶部时,它们消失了。只剩下9个中的2个。
from mypackage.data_transform.g1 import my_func
#!/usr/bin/python
VERSION = "0.1"
import os, sys, raindrop
from os import path
try:
import pygame
from pygame.locals import *
except ImportError, err:
print 'Could not load module %s' % (err)
sys.exit(2)
# main variables
WIDTH, HEIGHT, FPS = 300, 300, 30
# initialize game
pygame.init()
screen = pygame.display.set_mode((WIDTH,HEIGHT))
pygame.display.set_caption("Rain and Rain")
# background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((40,44,52))
# blitting
screen.blit(background,(0,0))
pygame.display.flip()
# clock for FPS settings
clock = pygame.time.Clock()
def main():
raindrops = pygame.sprite.Group()
# a function to create new drops
def newDrop():
nd = raindrop.Raindrop()
raindrops.add(nd)
# creating 10 rain drops
for x in range(0,9): newDrop()
# variable for main loop
running = True
# event loop
while running:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.blit(background,(100,100))
raindrops.clear(screen,background)
raindrops.update()
raindrops.draw(screen)
pygame.display.flip()
pygame.quit()
if __name__ == '__main__': main()
答案 0 :(得分:1)
0,1,2,3,4
ab,b,Ge,Stas,sap
cd,,TT,,d3
,,,,ch99
问题是有些降雨量会超过if self.rect.y == HEIGHT:
,因为HEIGHT
是范围[1,8]中的随机数,因此speedy
的多个可能无法被{{{1}整除1}}。例如speedy
,2*HEIGHT
从-HEIGHT = -300变为-293,-286,...,295,然后变为302,大于300,因此speedy = 7
检查永远不会是真的,雨水会永远消失。
对rect.y
的简单更改将解决问题:
==