Code: Alles auswählen
if event.type == MOUSEBUTTONDOWN:
x1 = 500
y1 = 500
Bamba
Code: Alles auswählen
if event.type == MOUSEBUTTONDOWN:
x1 = 500
y1 = 500
Code: Alles auswählen
x = 100
y = 100
screen.fill(black)
screen.blit(surface, (x, y))
pygame.display.flip()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
(x1, y1) = pygame.mouse.get_pos()
screen.fill(black)
screen.blit(surface, (x1, y1))
pygame.display.flip()
Dazu brauchst Du mindestens ein "Flag" wo vermerkt wird, ob das Bild noch angeklickt werden muss, oder ob Du schon in der "Bild bewegen" Phase bist.Bamba hat geschrieben:Wie bekomme ich es hin, dass man ein Bild "anklicken" kann und nur dieses Bild dann mit den obenstehenden Codezeilen mit weiteren Mausklicks irgendwohin geschickt wird?
Code: Alles auswählen
import pygame
class MovableObject(object):
def __init__(self, surface, position=(0, 0)):
self.surface = surface
self.position = position
def draw_on(self, surface):
surface.blit(self.surface, self.position)
def is_hit(self, (x, y)):
return self.surface.get_rect(topleft=self.position).collidepoint(x, y)
def main():
pygame.display.init()
screen = pygame.display.set_mode((640, 480))
surface = pygame.Surface((10, 10))
surface.fill((255, 255, 255))
BLACK = (0, 0, 0)
screen.fill(BLACK)
picture = MovableObject(surface, (100, 100))
picture.draw_on(screen)
pygame.display.flip()
is_activated = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
coordinates = pygame.mouse.get_pos()
if not is_activated:
is_activated = picture.is_hit(coordinates)
else:
screen.fill(BLACK)
picture.position = coordinates
picture.draw_on(screen)
pygame.display.flip()
Code: Alles auswählen
line 13, in is_hit
return self.surface.get_rect(topleft=self.position).collidepoint(x, y)
TypeError: get_rect() takes no keyword arguments
Dann aktualisier mal auf das aktuelle 1.7.1, da sollen viele Sachen erweitert/dazugekommen sein.Bamba hat geschrieben:Ich habe pygame 1.6
Code: Alles auswählen
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
coordinates = pygame.mouse.get_pos()
if not is_activated:
is_activated = picture.is_hit(coordinates)
if picture == coordinates:
if event.type == pygame.MOUSEBUTTONDOWN:
coordinates = pygame.mouse.get_pos()
picture.position = coordinates
picture.draw_on(screen)
pygame.display.flip()
elif picture2 == coordinates:
if event.type == pygame.MOUSEBUTTONDOWN:
coordinates = pygame.mouse.get_pos()
picture.position = coordinates
picture.draw_on(screen)
pygame.display.flip()