我目前正在尝试更改我在 PySDL2 中创建的窗口的位置,在它已经被渲染之后。
我试过更新Window.position
窗口的属性。但是尽管这样做了,并且让表面自行刷新,但没有可见的变化。(窗口停留在最初绘制的位置)。
我知道我可以更改窗口位置,因为如果我更改窗口创建行中的位置,它会在最初绘制在屏幕上时发生更改。(你只是似乎无法改变它之后)
代码:
import sdl2
import sdl2.ext
import sys
White = sdl2.ext.Color(255,255,255)
Red = sdl2.ext.Color(153,0,0)
class Background(sdl2.ext.SoftwareSpriteRenderSystem):
def __init__(self,window):
super(Background,self).__init__(window)
sdl2.ext.fill(self.surface,sdl2.ext.Color(0,33,66))
def main():
sdl2.ext.init() # Initialze
world = sdl2.ext.World() # Create World
W = sdl2.ext.Window("Default",size=(400,300), position = None,flags = sdl2.SDL_WINDOW_BORDERLESS) # Create Window
BG = Background(W)
world.add_system(BG)
W.show()
running = True
while running:
events = sdl2.ext.get_events()
for event in events:
if event.type == sdl2.SDL_QUIT:
running = False
break
if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
X,Y = (300,100) # NEW COORDINATES
print("Updating: . . ")
W.position = X,Y # Updating the coordinates
print(W.position)
W.hide() # Tried hiding and showing the window
W.show() # Didn't help unfortunately
W.refresh() # Refresh the window.
return 0
if __name__ == "__main__":
sys.exit(main())
我的尝试只是更新窗口的 .position 属性。但就像我之前所说的,似乎什么都没有发生。
编辑:根据这篇博文。这几乎是不可能的。