pandorasbox
Still Fresh
- Joined
- Jan 15, 2013
- Messages
- 3
Hi! I am trying to figure out how to click and drag and drop any item on pygame. I was testing with a simple circle and this is what I have:
from pygame import *
screen=display.set_mode((600,400))
running=True
while running:
for evnt in event.get():
if evnt.type == QUIT:
running=False
x,y=mouse.get_pos()
b=mouse.get_pressed()
if evnt.type == MOUSEBUTTONDOWN:
if evnt.button == 1:
screencopy=screen.copy()
if b[0] == 1:
screen.blit(screencopy,(0,0))
draw.circle(screen,(255,0,0),(x,y),20)
display.flip()
quit()
I have a couple problems. Firstly although it does drag and drop, when your mouse is first pressed down another circle will also appear where you first clicked so now you have one permanent circle and another one that is being dragged. My second problem is that once you let go and the circle is "dropped", and you click again with in a certain time frame (I think that's the problem), the old circle disappears and your mouse begins to drag a new one.
Could I get some help please? I would really like it if you could use what I have here and tweak it just a little? Because I really would like the code to be really basic as it is now since I am a very very new beginner and barely understand any of the other code I've seen online.
The second problem is not as big a deal, though. I'd be happy with just the first one solved.
Thanks!
from pygame import *
screen=display.set_mode((600,400))
running=True
while running:
for evnt in event.get():
if evnt.type == QUIT:
running=False
x,y=mouse.get_pos()
b=mouse.get_pressed()
if evnt.type == MOUSEBUTTONDOWN:
if evnt.button == 1:
screencopy=screen.copy()
if b[0] == 1:
screen.blit(screencopy,(0,0))
draw.circle(screen,(255,0,0),(x,y),20)
display.flip()
quit()
I have a couple problems. Firstly although it does drag and drop, when your mouse is first pressed down another circle will also appear where you first clicked so now you have one permanent circle and another one that is being dragged. My second problem is that once you let go and the circle is "dropped", and you click again with in a certain time frame (I think that's the problem), the old circle disappears and your mouse begins to drag a new one.
Could I get some help please? I would really like it if you could use what I have here and tweak it just a little? Because I really would like the code to be really basic as it is now since I am a very very new beginner and barely understand any of the other code I've seen online.
The second problem is not as big a deal, though. I'd be happy with just the first one solved.
Thanks!