[英]Randomly blitting in Pygame
im making a basic pygame and I was wondering if anyone can help me out 我正在制作一个基本的pygame,我想知道是否有人可以帮助我
so after a certain amount of time a power-up scrolls down the screen but I cant get it to work 因此,经过一定时间后,开机会在屏幕上向下滚动,但我无法正常工作
here is the method im using: 这是即时通讯使用的方法:
def random_event(self):
self.force_img_r = self.force_img.get_bounding_rect()
self.rnd_x = random.randint(5,315)
self.force_img_r.x = self.rnd_x
self.force_img_r.y += 3
screen.blit(self.force_img,(self.rnd_x, self.force_img_r.y))
all its doing is the image is blinking for a split second then nothing 它所做的只是图像闪烁了一秒钟,然后什么也没有
can anyone tell me why its not working!? 谁能告诉我为什么它不起作用!?
In pygame you usually have a main loop that cleans the screen on every iteration, that's probably why you only see a blink, you draw and in the next loop you clean again. 在pygame中,通常会有一个主循环在每次迭代时清理屏幕,这可能就是为什么您只看到眨眼,绘制并在下一个循环中再次清理的原因。
To work arround this, in pygame events should only update game state, and draw the screen on every loop according to the current state. 要解决此问题,在pygame中,事件仅应更新游戏状态,并根据当前状态在每个循环上绘制屏幕。
Some pseudocode: 一些伪代码:
# Main Loop
while True:
# Process events
# -> Update game state
# Clean screen
# Draw current state to the screen
# Update or flip display
# Keep framerate (clock.Tick())
You can call external classes/methods/functions, but you should always keep this structure at the main loop. 您可以调用外部类/方法/函数,但应始终将此结构保留在主循环中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.