Pygame 旋转行删除旧行 [英] Pygame rotate line delete old line
本文介绍了Pygame 旋转行删除旧行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 math
模块在 pygame 中旋转一行,每隔一秒旋转一行删除旧行.我刚刚使用了其他代码,但问题是旧线旋转,所以我看到了阳光效果.
解决方案
为了轻松地帮助您找到问题的具体答案,您确实需要展示您的代码.请参阅
How can I rotate a line in pygame using math
module and every second rotate line delete old line. I've just used other code but the problem was old line rotate and so I watched an sunshine effect.
解决方案
To easily assist you with a specific answer for your problem, you really need to show your code. Please see how to ask.
I've prepared a generic example that randomises one end point of a line when a mouse button is clicked.
# pyg_line_demo
import pygame
import random
def get_random_position():
"""return a random (x,y) position in the screen"""
return (random.randint(0, screen_width - 1), #randint includes both endpoints.
random.randint(0, screen_height - 1))
def random_line(line):
""" Randomise an end point of the line"""
if random.randint(0,1):
return [line[0], get_random_position()]
else:
return [get_random_position(), line[-1]]
# initialisation
pygame.init()
screen_width, screen_height = 640, 480
surface = pygame.display.set_mode((screen_width,screen_height))
pygame.display.set_caption('Lines')
clock = pygame.time.Clock() #for limiting FPS
FPS = 30
# initial line
line = [(10, 10), (200, 200)]
finished = False
while not finished:
for event in pygame.event.get():
if event.type == pygame.QUIT:
finished = True
if event.type == pygame.MOUSEBUTTONDOWN:
line = random_line(line)
#redraw background
surface.fill(pygame.Color("white"))
#draw line
pygame.draw.aalines(surface, pygame.Color("blue"), False, line)
# update display
pygame.display.update()
#limit framerate
clock.tick(FPS)
pygame.quit()
You should be able to insert your line rotation function in place of the random_line()
function.
Let us know if you have any further questions.
这篇关于Pygame 旋转行删除旧行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文