简体   繁体   English

如何在 pygame 中将图像闪电战到屏幕上

[英]How to make images blitz onto the screen in pygame

This is the code for the grid.这是网格的代码。 I am using this in a separate file which is being called into the main file to get the units onto the screen.我在一个单独的文件中使用它,该文件被调用到主文件中以将单位显示在屏幕上。

import pygame

pygame.init()

Background = pygame.display.set_mode((900 ,900))
Green = (45,198,14)
Background.fill(Green)

for i in range(0, 900, 50):
    pygame.draw.line(Background, (0, 0, 0), (0, i), (900, i))
    pygame.draw.line(Background, (0, 0, 0), (i, 0), (i, 900))
pygame.display.update()

while pygame.event.wait().type != pygame.QUIT:
    pass

This is the code that i have used to try get the image onto the screen:这是我用来尝试将图像显示在屏幕上的代码:

import GridV5
import pygame

pygame.init()

RedInfantry= pygame.image.load("H:\computer science\6.2\Coursework\Week\Red team\InfantryRedV20.gif")



while True:
    Background.blit(RedInfantry,(0,0))

I have tried with other units however none will appear on the screen.我曾尝试使用其他单位,但屏幕上不会出现任何单位。

The function is 'blit' not 'blitz' so try changing that first.该功能是“闪电战”而不是“闪电战”,因此请先尝试更改它。 See docs here在此处查看文档

https://www.pygame.org/docs/ref/surface.html https://www.pygame.org/docs/ref/surface.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM