我想在pygame中创建一个游戏,我在另一个文件(sprite)中创建一个类,然后将im导入到我的主文件中,但是我不知道如何在窗口上绘制它
我在很多论坛上都看过,但是找不到解决方法。
那是我的精灵代码:
class Cursor(pygame.sprite.Sprite):
def __init__(self, color, width, height):
# Call the parent class (Sprite) constructor
pygame.sprite.Sprite.__init__(self)
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
self.image = pygame.Surface([width, height])
self.image.fill(white)
# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rect = self.image.get_rect()
这是我的主文件:
import pygame
from modules.setting import *
from modules.colors import *
from sprites.cursor import *
pygame.init()
window = pygame.display.set_mode((setting.width, setting.height))
pygame.display.set_caption("Civ1")
#variable
cursor = Cursor(colors.white, 20, 30)
loop = True
while loop:
for event in pygame.event.get():
if (event.type==pygame.QUIT):
loop = False
window.fill(colors.black)
pygame.cursor.draw(window)
pygame.display.flip()
pygame.quit()
我尝试使用draw函数,但是它不起作用