简体   繁体   English

我需要检查我的鼠标是否在窗口内以 blit 自定义光标

[英]I need to check if my mouse is inside the window to blit a custom cursor

As i said I'm trying to check if my mouse is inside the window to blit an external cursor that i downloaded as a png, because when the mouse leaves the window the cursor image will freeze at the last place my mouse was in before leaving the window.正如我所说,我正在尝试检查我的鼠标是否在窗口内,以对我下载为 png 的外部光标进行 blit,因为当鼠标离开窗口时,光标图像将冻结在鼠标离开前的最后一个位置窗户。

here is my code inside the game loop:这是我在游戏循环中的代码:

 x, y = pg.mouse.get_pos()
 if x > 0 and x < MAX_X and y > 0 and y < MAX_Y:
    screen.blit(cursor, cursorRect)

and before the loop:和循环之前:

screen = pg.display.set_mode((1316,740))    
MAX_X, MAX_Y = screen.get_size()

The problem is that the code works for the upper part and left part of the window but it doesnt affect the right and bottom.问题是代码适用于窗口的上部和左侧,但不影响右侧和底部。

I solved it while typing the question by checking if the x and the y are smaller than the window size - 1我在输入问题时通过检查 x 和 y 是否小于窗口大小来解决它- 1

thought i'd leave it here to spare any newbies like me 30 minutes of their time:以为我会把它留在这里,以节省像我这样的新手 30 分钟的时间:

if x > 0 and x < MAX_X - 1 and y > 0 and y < MAX_Y - 1:
    screen.blit(cursor, cursorRect)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM