首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对象随鼠标移动(Python)

问对象随鼠标移动(Python)
EN

Stack Overflow用户
提问于 2016-05-09 00:47:24
回答 1查看 645关注 0票数 0

下面这行代码,我已经借用作为一个例子来使用。它所做的是获取一个字符串,并在pygame中将其打印出来,然后这行将跟随鼠标移动到哪里。我只是想知道如何更改draw.circle的字符串行,我总是得到一个错误。干杯!在下面的代码中,有问题的字符串是“最后按下的按钮是”。

代码语言:javascript
复制
from pygame import * 
init()
size = width, height = 800, 600
screen = display.set_mode(size)
button = 0
BLACK = (0, 0, 0)
RED = (255, 255, 255)
font = font.SysFont("Times New Roman",30)

def drawScene(screen, mx, my, button):
    draw.rect(screen, BLACK, (0, 0, width, height))
    # Draw circle if the left mouse button is down.
    string = "The last button pressed is " + str(button) + "."
    text = font.render(string, 1, RED)
    size = font.size(string)
    screen.blit(text, Rect(mx, my, size[0], size[1]))
    display.flip()

running = True
myClock = time.Clock()

mx = my = 0
# Game Loop
while running:
    for evnt in event.get():             # checks all events that happen
        if evnt.type == QUIT:
            running = False
        if evnt.type == MOUSEBUTTONDOWN:
            mx, my = evnt.pos          
            button = evnt.button
        if evnt.type == MOUSEMOTION:
            mx, my = evnt.pos
    drawScene(screen, mx, my, button)
    myClock.tick(60)                     # waits long enough to have 60 fps

quit()
EN

回答 1

Stack Overflow用户

发布于 2016-05-09 05:45:26

这将在mx,my:处绘制一个5像素半径的圆:

代码语言:javascript
复制
pygame.draw.circle(screen, BLACK, (mx, my), 5)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37102305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档