私はpygameを使ってpythonでpurple rain programを作ろうとしています。私はRainと呼ばれるクラスを作って複数の雨滴を作ったが、雨のオブジェクトが1つしか落ちなかったらテストを試みたが、そうではなかったし、何が間違っているのか分からないようだ。これはnoobyと非常に明白な質問かもしれませんが、私はまだPygameとPythonを学んでいることを覚えておいてください。Pygameを学ぶ、なぜこの 'raindrop'(Rectオブジェクト)が倒れるのでしょうか?
import pygame, sys
from pygame.locals import *
import random
pygame.init()
FPS = 60
BLACK = (0,0,0)
WHITE = (255,255,255)
PURPLE = (130, 50, 200)
screen_resolution = (800, 600)
screen = pygame.display.set_mode(screen_resolution)
pygame.display.set_caption('Purple Rain')
clock = pygame.time.Clock()
gameLoop = True
class Rain:
def __init__(self, x, y, width, height, yspeed):
self.rect = pygame.Rect(x,y,width,height)
self.yspeed = yspeed
self.x = x
self.y = y
def fall(self):
self.rect.move(self.x, self.y - self.yspeed)
def draw(self):
pygame.draw.rect(screen, PURPLE, self.rect)
drop = Rain(400,300,2,20,9)
while gameLoop:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
screen.fill(WHITE)
drop.draw()
drop.fall()
pygame.display.flip()
clock.tick(FPS)
http://stackoverflow.com/questions/19369112/rect-move-does-not-move-the-rect –