How To Drag And Drop Items In Pygame

  Рет қаралды 29,279

Coding With Russ

Coding With Russ

Күн бұрын

In this video I will explain how to drag and drop items in pygame.
I'll show how to use the event handler to select a box and move it around with the mouse.
For the full source code and step by step explanation head over to my website: www.codingwithr...

Пікірлер: 29
@walkastray007
@walkastray007 11 ай бұрын
Hey sorry I'm late! I'm glad I could find your tutorial because it's actually exactly what I am looking for. Whenever I searched drag and drop, it would only give me tutorials on making things "snappy" rather than leaving the item where your mouse is on the screen.
@davecolburn1378
@davecolburn1378 Жыл бұрын
Excellent example -- short, to the point, very clear.
@CodingWithRuss
@CodingWithRuss Жыл бұрын
Thanks!
@orum7761
@orum7761 10 ай бұрын
subscribed after 2 videos.
@aaronjayanmathew6745
@aaronjayanmathew6745 Жыл бұрын
Thanks for your amazing tutorial
@CodingWithRuss
@CodingWithRuss Жыл бұрын
Thanks, glad you liked it
@ricardoaa2524
@ricardoaa2524 Жыл бұрын
Gracias, tus enseñanzas son magistrales!!!!
@CodingWithRuss
@CodingWithRuss Жыл бұрын
De nada :)
@Dayplaylist
@Dayplaylist Жыл бұрын
Ооо это очень полезная информация 😌👍👍👍👍
@CodingWithRuss
@CodingWithRuss Жыл бұрын
Spasibo :)
@0lio_325
@0lio_325 Жыл бұрын
Cannot find reference 'collidepoint' in 'Surface | SurfaceType' Cannot find reference 'move_ip' in 'Surface | SurfaceType' i get these errors and idk why. the pygame window opens, but then i click on anything it crashes D:
@KIRANTS-s5w
@KIRANTS-s5w Жыл бұрын
Hello. What if i only want to move them using the corners only? Thank you in advance
@Formulaah
@Formulaah Жыл бұрын
Hey Russ! Could you tell me how to make it when MOUSEBUTTONUP the boxes have gravity and they fall to a surface? So they have gravity in general and you can pick them up and when MOUSEBUTTONUP they fall again.
@CodingWithRuss
@CodingWithRuss Жыл бұрын
Hello, yes sure, I have a couple videos explaining how to add gravity. This one should help: kzbin.info/www/bejne/qWaWhWmbh8mNptk
@Formulaah
@Formulaah Жыл бұрын
@@CodingWithRuss Thanks man! You’re my favorite KZbinr!! ❤❤
@alexanderwolter
@alexanderwolter 10 ай бұрын
Thanks for the video. In my version the boxes appear one after another every time when I click to close the window. I wanted all boxes to appear directly at the beginning. Can anyone help and tell me what I did wrong? Thanks in advance
@fuzzy-02
@fuzzy-02 5 ай бұрын
Hey man, what if I have a grid of hundreds of boxes. Wouldn't this be terribly slow to check if my mouse is clicking on which box
@CodingWithRuss
@CodingWithRuss 5 ай бұрын
For a grid based game I would use a different approach and actually split the screen into a grid. Then you can check the mouse coordinates and work out where on the grid your mouse is. That narrows down the collision checks that you have to do because you would be looking inside a specific grid square at that point.
@chrisnorthall8317
@chrisnorthall8317 Жыл бұрын
just (well nearly) what I was looking for, I want to only drag in X and Y but struggling to do so. Any ideas? (btw, nearly finished your Udemy platformer!)
@CodingWithRuss
@CodingWithRuss Жыл бұрын
Hi, sure I can try to help, what do you mean by only drag in X and Y though? Do you want to make it so a box is restricted to only move left and right or up and down? Like menu sliders? The event.rel variable is used to track mouse motion in x and y coordinates, but if you wanted to only move in the X axis for example then you could modify the move code to be move_ip(event.rel[0], 0). This way it would move along the x axis but not the y axis. You can do the same thing for vertical movement by swapping those round and using event.rel[1].
@tacobeartaco7140
@tacobeartaco7140 Жыл бұрын
Love your videos, man! How do I go about moving a .png that I've got on the screen?
@CodingWithRuss
@CodingWithRuss Жыл бұрын
You can still use a rectangle for working out positions, but instead of actually drawing the rectangle, you can blit an image at the rectangle's x and y coordinates
@-_Nuke_-
@-_Nuke_- Жыл бұрын
is there a tutorial for making the boxes transparent so that you can look through them?
@dohg678
@dohg678 Жыл бұрын
You want to change the colour from “purple” to a tuple e.g. (150, 0, 150, 100). The first 3 values are the colour values, which should give a purple colour. The last value is how opaque you want it to be. Hope that helps :)
@lightingzr
@lightingzr Жыл бұрын
if we want to, how can we change the number of blocks?
@CodingWithRuss
@CodingWithRuss Жыл бұрын
The for loop for i in range(5) determines how many blocks you make. So you can change the number 5 to make as many as you need
@justin7oo994
@justin7oo994 Жыл бұрын
Could you please make a tutorial on tile collisions for platformers ?
o3-mini-high makes a simple LoR clone
3:59
rasuru dev
Рет қаралды 23
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
🚀 Unlocking AI’s Business Impact with Anton Abrarov
1:00:23
Michael Coppola
Рет қаралды 801
How to Make Beautiful Code Presentations
9:59
code_report
Рет қаралды 126 М.
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Coding With Russ
Рет қаралды 1 МЛН
This React Drag and Drop Component Is Magic
9:56
developedbyed
Рет қаралды 105 М.
How to Track the Mouse Position in PyGame! (Python GUI Tutorial)
6:15
A New Drag And Drop Library For EVERY Framework
16:02
Theo - t3․gg
Рет қаралды 183 М.
Pygame Tutorial - Creating Space Invaders
1:56:03
Tech With Tim
Рет қаралды 819 М.
PyGame Beginner Tutorial in Python - Adding Buttons
18:55
Coding With Russ
Рет қаралды 182 М.
Move Things With The Mouse - PyGame Thursdays 2
12:41
Codemy.com
Рет қаралды 4 М.
Much bigger simulation, AIs learn Phalanx
29:13
Pezzza's Work
Рет қаралды 2,9 МЛН