【发布时间】:2015-10-09 01:14:45
【问题描述】:
这是对以下代码的后续问题。
我注释掉了 y imgPos,所以图像只能向左或向右拖动。但是您可以在任一方向上永久拖动图像。你怎么能设置一个停止点,这样你就不能再左右拖动它了。
我试过 imgPos.clamp_ip(screen)
import pygame
from pygame.locals import *
pygame.display.init()
screen = pygame.display.set_mode((800, 600))
img = pygame.image.load('sky.png')
imgPos = pygame.Rect((0, 0), (0, 0))
LeftButton = 0
while 1:
for e in pygame.event.get():
if e.type == QUIT: exit(0)
if e.type == MOUSEMOTION:
if e.buttons[LeftButton]:
# clicked and moving
rel = e.rel
imgPos.x += rel[0]
#imgPos.y += rel[1]
screen.fill(0)
screen.blit(img, imgPos)
pygame.display.flip()
pygame.time.delay(30)
【问题讨论】:
标签: pygame