Python 如何使用pygame.surface.scroll()?
我刚刚了解了pygame.surface.scroll(),我从pygame文档中了解到,Python 如何使用pygame.surface.scroll()?,python,pygame,Python,Pygame,我刚刚了解了pygame.surface.scroll(),我从pygame文档中了解到,scroll()用于移动曲面,而无需重新构建背景以覆盖旧曲面,就像pygame.rect.move_ip()用于曲面一样 无论如何,我不知道如何使用它,只要我是初学者,pygame文档中的示例对我来说就很难理解,在搜索了很长时间后,我找不到任何有用的东西来理解如何使用它 这是我的密码 import pygame from pygame.locals import* screen=pygame.displa
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)
编辑:您的
图像
和屏幕
变量是向后的。我敢肯定,这也给你带来了一些困惑
你的问题可能是你试图滚动一个全黑的背景。它可能在滚动,而您只是不知道它,因为您使用blit()
在屏幕上绘制的白色框是静止的
尝试使用你能看到的滚动条,比如图像文件。如果你想移动白盒,你可以添加一个计数器作为速度变量。阅读这个,然后运行它
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))
speed = 5 # larger values will move objects faster
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)
# I did modulus 720, the surface width, so it doesn't go off screen
screen.blit(image,((boxx + speed) % 720, (boxy + speed) % 720))
pygame.display.update()
clock.tick(60)
我不能确定scroll函数是否正常工作,请学习使用图像作为背景,以便您可以首先看到它的移动。多谢各位。是的,这是我制作黑色背景的错误,我应该制作screen.scroll()而不是image.scroll()@。