[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] how to get point where is an image ...





On 10/11/05, Peter Shinners <pete@xxxxxxxxxxxx> wrote:
On Tue, 2005-10-11 at 17:26 -0300, Juan Reyes López wrote:

>  the problem is that I am doing a "drag & drop" so the position  is
> changed to  the mouse position when the button 1 is pressed, so I just
> want to know if there is some "magic" function that returns the point
> where is the player o I have do it by my self ..

If you mean the mouse cursor, you can call pygame.mouse.get_pos() to
find the current position.

http://pygame.org/docs/ref/mouse.html#pygame.mouse.get_pos

 
no, I mean the place where is the image after I had moved it. This is my code (I want drag and drop for player)

import os,pygame
from pygame.locals import *

global position
screen = pygame.display.set_mode((640, 480))
player = pygame.image.load('player.jpg').convert()
background = ""> screen.blit(background,(0,0))
position = player.get_rect()
screen.blit(player,position)
pygame.display.update()
while 1:
   
    pygame.event.pump()
    n = player.get_rect()
    boton = pygame.mouse.get_pressed();
    mouse_pos = pygame.mouse.get_pos();
    img_x_sup = n[0] + n[2]
    img_x_inf = n[0]
    img_y_inf = n[1]
    img_y_sup = n[1] + n[3]

   
    if boton[0] == 1 and mouse_pos[0]>img_x_inf and mouse_pos[0]<img_x_sup and mouse_pos[1]>img_y_inf and mouse_pos[1]<img_y_sup:
        global position
        position[0] = mouse_pos[0]
        position[1] = mouse_pos[1]
        screen.blit(background,(0,0))
        screen.blit(player,position)
        print player.get_offset()
        pygame.display.update() 

Actually all I need is an "drag and drop", and I'm trying to do it, ¿there's other way to get drag and drop? tks for you patience Peter