python - 移动游戏背景不重绘本身
问题描述
所以我试图制作一个移动的背景,但是背景并没有连续移动。它显示黑屏,背景不会连续闪烁,给人的印象是背景在移动。
#Game background
background = pg.transform.scale(pg.image.load('splash.jpg'), (WIDTH,HEIGHT))#background size being adjusted to fit a particular screen size
background_xpos = 0 #the x position of the background is at 0 of (0,0)
background_xpos2 = background.get_width() #obtains the width of the background at a certain coordinate
def UpdateGame():
window.blit(background,(background_xpos,0))
window.blit(background,(background_xpos,0))
pg.display.update()
run = True #while the game is running
while run:
screen.fill((0,0,0))
clock.tick(FPS) #determines the amount of frames per second
background_xpos = background_xpos - 2
background_xpos2 = background_xpos - 2
if background_xpos < background.get_width() * -1:
background_xpos = background.get_width()
if background_xpos2 < background.get_width() * -1:
background_xpos2 = background.get_width()
解决方案
中有一个错字UpdateGame
。更改background_xpos
为background_xpos2
第 2 行UpdateGame
:
window.blit(background,(background_xpos,0))
window.blit(background,(background_xpos2,0))
推荐阅读
- vb.net - 如何管理任务以便跟踪状态/取消
- windows - UFT 14.03 未识别(也未记录)Web Chrome Beta 72 对象
- scikit-learn - 在训练之前执行图形切割或作为基于像素的分类的后处理
- google-cloud-platform - 使用服务帐户时项目 XXX 的容器分析.occurrences.get 被拒绝
- javascript - 如何在角度创建自定义类型
- javascript - 如何进行登录验证
- python - pandas Series.index 行为不允许在单行操作中重新分配索引
- python - 确定对象的类型是否与通过类型模块定义的嵌套类型匹配
- python - 报纸python缓存问题,每次调用相同的输出
- javascript - ReferenceError onclick JavaScript