2
私は学校プロジェクトのpygameで描画プログラムを作ろうとしています。このモジュールでは、ユーザーがマウスを押して、サーフェス上に線を引くことを意図しています。人が矩形を押し下げると、選択した人物の色は、描かれた線の色になります。何らかの理由で、変数が変更されることがありますが、マウスを押しても、線は描画されません。これでコードブロック:私はどうなるのかpygameで線を引いて色を変更するにはどうすればいいですか?
def painting_module():
running = True
while running:
#clock for timingn processes
Clock.tick(FPS)
# Process input (event)
for event in pygame.event.get():
Mouse_location = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
displacement_val = pygame.mouse.get_rel()
color_to_paint_with = (0,0,0)
if event.type == pygame.QUIT:
running = False
if click[0] == 1:
# Intended to select colors if pressed, draw a line if the mouse is not on the rect
if red_rect.collidepoint(Mouse_location):
color_to_paint_with = RED
print "Red"
print color_to_paint_with
if green_rect.collidepoint(Mouse_location):
color_to_paint_with = GREEN
print "red"
print color_to_paint_with
if blue_rect.collidepoint(Mouse_location):
color_to_paint_with = BLUE
print "red"
print color_to_paint_with
if gray_rect.collidepoint(Mouse_location):
color_to_paint_with = GRAY
print "red"
print color_to_paint_with
if eraser_ivory_rect.collidepoint(Mouse_location):
color_to_paint_with = IVORY
print "red"
print color_to_paint_with
#draws the line
pygame.draw.line(Screen, color_to_paint_with, Mouse_location, (Mouse_location[0] + displacement_val[0], Mouse_location[1] + displacement_val[1]))
まだ色を選択する必要があります。私はrectを押すと、私は色を選択します。この変数はpygame.draw.lineに渡されます。どのようにwhileループを使うのが好きですが、どのように色を選択できますか? – programmer
私はループの前に、あなたがしたコードを使用し、同じ方法で色を選択させると思います。次に、パラメータとしてタプル(color_to_paint_with)をとり、色が選択されたときにこの関数を呼び出す関数のwhileループ中に入れます。 – Akinni
私はこれが役立つことを願っています – Akinni