我刚刚了解了pygame.surface.scroll()
,并且我从pygame文档中了解到,scroll()
用于移动曲面,而不需要再次重建背景来覆盖旧曲面,就像pygame.rect.move_ip()
一样,但是对于曲面。在
总之,我不知道如何使用它,而且pygame文档中的示例对我来说很难理解,只要我是初学者,在搜索了很长时间之后,我没有找到任何有用的东西来理解如何使用它。在
这是我的密码。在
import pygame
from pygame.locals import*
screen=pygame.display.set_mode((1250,720))
pygame.init()
clock=pygame.time.Clock()
boxx=200
boxy=200
image = pygame.Surface([20,20]).convert_alpha()
image.fill((255,255,255))
while True :
screen.fill((0,0,0))
for event in pygame.event.get():
if event.type==pygame.QUIT :
pygame.quit()
quit()
image.scroll(10,10)
screen.blit(image,(boxx,boxy))
pygame.display.update()
clock.tick(60)
编辑:您的
image
和screen
变量是向后的。我敢肯定,这也给你带来了一些困惑。。在你的问题可能是你试图滚动一个全黑的背景。它可能是滚动的,你只是不知道,因为你用
blit()
在屏幕上绘制的白色框是静止的。在尝试使用一些你可以看到滚动的东西,比如图像文件。如果你想移动白盒子,你可以添加一个计数器作为速度变量。读这个,然后运行它。在
我不能确定滚动功能是否有效,学习使用图像作为背景,这样你就可以看到它首先移动。在
相关问题 更多 >
编程相关推荐