python - pygame - 移动图形(演员)
问题描述
我只是在用 Pygame 做一个小游戏。对象应该在屏幕上移动。当我尝试这样做时,总是拖着一条“轨道”(见图)。如何在不绘制运动“路线”的情况下移动苹果?
from random import randint
import pygame
WIDTH = 800
HEIGHT = 800
apple = Actor("apple")
apple.pos = randint(0, 800), randint(800, 1600)
score = 0
def draw():
apple.draw()
screen.draw.text("Punkte: " + str(score), (700, 5), color = "white")
def update():
if apple.y > 0:
apple.y = apple.y - 4
else:
apple.x = randint(0, 800)
apple.y = randint(800, 1600)
解决方案
这不是纯粹的 pygame,它是Pygame Zero。您必须调用screen.clear()
以清除每一帧中的显示:
def draw():
screen.clear()
apple.draw()
screen.draw.text("Punkte: " + str(score), (700, 5), color = "white")
推荐阅读
- spring - 使用 BLOB 类型将图像存储在数据库中
- batch-file - 如何打印过滤后的属性值 A 的值 B?
- javascript - 通过迭代创建的表格单元格是隐藏的 - 如何使用按钮取消显示每个条目?
- c++ - 找到满足浮点不等式的最小整数
- html - 如何从html页面中删除一些特定数据?
- java - 如何一次更改类的所有实例的实例变量,Java
- here-olp - 尝试发布到索引层时,收到错误为
创建数据框时不是术语 - c++ - 如何解决输出文件夹中缺少的 DLL?
- java - 检查进程是否是Windows中的java进程
- python - 为什么这个错误会出现“添加评论——重定向到错误的页面”?