python - How do I import a picture and put it on a pygame window
问题描述
I've been trying for a while now to make a destroyer type game using 'pygame' the main problem I have is importing a picture of a ship to use as the main player. And no matter what I try, I always get the same error
win.blit(win, char, (20, 20), (146, 149)) TypeError: an integer is required (got type tuple)
And this is my code:
import pygame
pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("First Game")
char = [pygame.image.load('char.png')]
run = True
while run:
win.fill((0,0,0))
win.blit(win, char, (20, 20), (146, 149))
pygame.display.update()
pygame.quit()
Any help would be appreciated.
解决方案
blit()
是一个实例方法。除了 的实例之外pygame.Surface
,必需的参数是必须blit
位于实例pygame.Surface
和位置上的 Surface。
此外,char
是具有 on 元素的表面列表。
char = [pygame.image.load('char.png')]
将其更改为:
char = pygame.image.load('char.png')
和blit
表面:char
_win
win.blit(char, (20, 20))
或者
pygame.Surface.blit(win, char, (20, 20))
请注意,area
参数 (of blit
) 必须是一个矩形,并表示要绘制的源 Surface 的较小部分
推荐阅读
- node.js - 具有express框架的nodejs中的acl权限
- oauth-2.0 - 如何在 GSuite 中创建 OAuth 2.0 应用程序仅供内部使用?
- swift - 在 Swift 4 中将可选字符串转换为 Int
- elixir - 如何有一个键值输出
- zabbix - Zabbix API - 有没有办法在特定时间范围内请求减少“趋势”或“历史”记录的数量
- wordpress - 如何创建一个循环,其中循环更改自定义帖子类型中的每个帖子?
- spring-boot - 单次注销问题
- java - 通过 Intent 拍摄照片
- hystrix - 如何在 feignClient 中使用隔板?
- stripe-payments - 购买完成后更改条纹结帐按钮