在继续前进之前等待慕斯
哟, 因此,我正在尝试从事一个非常简单的游戏,从本质上讲,您只有一个窗口,每当您按Pygame.mouse.get_pos()数据时,存储了一个窗口。 我遇到的问题是等待另一个鼠标单击,以便我可以存储更多的鼠标位置数据,以便最终可以在2个鼠标之间绘制矩形/正方形。 代码:
import sys
import pygame as pg
import time
title = "draw rect thign"
running = True
pg.display.init()
surface = pg.display.set_mode(size=(400, 200))
color = (255,0,0)
pg.display.set_caption(title)
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if event.type == pg.KEYDOWN:
if event.key== pg.K_q:
pg.display.quit()
if event.type == pg.MOUSEBUTTONDOWN:
pos1 = pg.mouse.get_pos()
if event.type == pg.MOUSEBUTTONDOWN:
pos2 = pg.mouse.get_pos()
Yo,
so I'm trying to work on a very simple game, essentially you just have a window and whenever you press once the pygame.mouse.get_pos() data is stored.
The problem I have is waiting for another mouse click so I can store more mouse position data so I can eventually draw a rectangle/square between the 2 mouse clicks.
code:
import sys
import pygame as pg
import time
title = "draw rect thign"
running = True
pg.display.init()
surface = pg.display.set_mode(size=(400, 200))
color = (255,0,0)
pg.display.set_caption(title)
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if event.type == pg.KEYDOWN:
if event.key== pg.K_q:
pg.display.quit()
if event.type == pg.MOUSEBUTTONDOWN:
pos1 = pg.mouse.get_pos()
if event.type == pg.MOUSEBUTTONDOWN:
pos2 = pg.mouse.get_pos()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,每次鼠标单击时都可以创建一个列表并在此处添加坐标。不要忘记在下一轮比赛中清除列表。
To do this, it is enough to create a list and add coordinates there with each mouse click. Don't forget to clear the list for the next round of the game.