import pygame
from pygame.locals import *
pygame.display.init()
screen = pygame.display.set_mode((1143,677 ))
img = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.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]:
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)
我试图用多个图像来实现这一点,并且图像总是重叠,并且只能移动一个图像,所以尝试了以下方法:
import pygame
from pygame.locals import *
pygame.display.init()
screen = pygame.display.set_mode((1143,677 ))
img = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png")
img1 = pygame.image.load(r"C:\Users\ga-sa\Downloads\03.png")
imgPos = pygame.Rect((0, 0), (0, 0))
imgPos1 = pygame.Rect((1, 1), (1, 1))
LeftButton = 0
while 1:
for e in pygame.event.get():
if e.type == QUIT: exit(0)
if e.type == MOUSEMOTION:
if e.buttons[LeftButton]:
rel = e.rel
imgPos.x += rel[0]
imgPos.y += rel[1]
screen.fill(0)
screen.blit(img, imgPos)
screen.blit (img1, imgPos1)
pygame.display.flip()
pygame.time.delay(30)
所以图像重叠并且可以移动第二个图像,我想让两个图像用鼠标移动,我希望分别移动图像
蝴蝶不菲
相关分类