Cameras in Pygame

  Рет қаралды 114,353

Clear Code

Clear Code

Күн бұрын

A video about cameras in pygame, we will create 6 different cameras that should cover nearly every use case.
If you want to support me: / clearcode
(You also get lots of perks)
Social stuff:
Twitter - / clear_coder
Discord - / discord
Timestamps:
0:00:00 - Intro
0:01:24 - Project setup
0:05:36 - YSort Camera
0:15:23 - Player center camera
0:26:08 - Box camera
0:36: 59 - Keyboard control
0:41:25 - Mouse control
0:59:11 - Zoom
Project files
github.com/clear-code-project...

Пікірлер: 127
@MoviestarsEnglish
@MoviestarsEnglish 2 жыл бұрын
"Clear Code" is the best KZbin channel to learn Pygame. These videos are really awesome!
@Pridetoons
@Pridetoons 2 жыл бұрын
I wish we have something for Love2D too.
@LuisPereira-bn8jq
@LuisPereira-bn8jq 2 жыл бұрын
This is a very good channel for beginners to pygame, but there's a huge difference between learning "pygame" and learning "Python Programming".
@Blinkers2007GameDev
@Blinkers2007GameDev Жыл бұрын
and dafluffypotato
@joey546
@joey546 Жыл бұрын
@@Pridetoons I found that Challacade is a good channel for Love2D.
@eap9020
@eap9020 Жыл бұрын
true
@Gabriel-kn2ri
@Gabriel-kn2ri 2 жыл бұрын
Your videos are just insane. I can't imagine how much work you put into them, but please, never stop, they help me so much. You explain things in a really clear and clever way, thank you!
@Qustode
@Qustode Жыл бұрын
Every single one of your videos help me out in this pygame journey and every single time I find it more enjoyable to code. Thank you, keep it up with the amazing videos.
@anamariabalaban
@anamariabalaban 2 жыл бұрын
It's great that there are people with pedagogical grace, but it's really wonderful when they share their knowledge with beginners. Please don't stop what you're doing 💝
@ianmccurdy7705
@ianmccurdy7705 Жыл бұрын
I hope you enjoy making these videos as much as I enjoy watching them.
@cuaitzzz
@cuaitzzz Жыл бұрын
Great video! love the zoom part. I used to subsurface the display and scale it to make the zoom, but that limited my zoom to the display size. I like yours aproach better.
@namlasyruhdwohc6340
@namlasyruhdwohc6340 2 жыл бұрын
wow, I was literally thinking if you were going to ever post a video solely on cameras in pygame, and here you are.... thx dude
@_caracalla_
@_caracalla_ 2 жыл бұрын
this is perfect. hope you will never stop doing these kinds of contents.
@austinkowalczyk8616
@austinkowalczyk8616 2 жыл бұрын
Awesome video!! everything is explained so well and is really clean and well done!! Keep it up!!
@aaravgang685
@aaravgang685 2 жыл бұрын
Needed just this. Thank you so much!
@delloff9866
@delloff9866 2 жыл бұрын
Thanks, I've been waiting for camera tutorial
@pa-vl1kg
@pa-vl1kg 2 жыл бұрын
Many thanks Clear Code for your time. Developer/CyberSec here, python lover.
@hadimohammadi9752
@hadimohammadi9752 2 жыл бұрын
Best channel for learning pygame! Thanks Clear Code!
@Jimsydonk
@Jimsydonk 2 жыл бұрын
This looks insane! Makes me want to start learning python now
@anantchandak9574
@anantchandak9574 2 жыл бұрын
If you know hindi Search CodeWithHarry He tell python from 0
@ej6552
@ej6552 2 жыл бұрын
Python is so easy to learn for me like who’s never learned any programming languages. Why don’t you try😃
@sweetchaos22
@sweetchaos22 2 жыл бұрын
I say do it. Even as just a hobby, it's been massively rewarding.
@steveradtke1308
@steveradtke1308 2 жыл бұрын
you really are great at explaining these.
@Moprationsz
@Moprationsz 2 жыл бұрын
I love your videos! Please do the sim city one, it would be really nice to see how the graphics are made, and how to manage all the game logic. Thanks!!
@VerticalVertex
@VerticalVertex 2 жыл бұрын
thank you. basic stuff explained so well.
@AndeyKoiwai
@AndeyKoiwai 3 ай бұрын
The explanation in this video is very simple, so it's very easy to understand, for the problem in the last video I added master_zoom = self.internal_surf_size_vector * self.zoom_scale if master_zoom[0]
@peteraraujo4936
@peteraraujo4936 2 жыл бұрын
dude I love your videos please keep doing what you doing👍
@roddripf
@roddripf 2 жыл бұрын
The next tutorial: Metroidvania? I love your lessons, thank you!
@sifacrbn5825
@sifacrbn5825 2 жыл бұрын
one of the best proggraming tutorial channel👍👍👍
@StarFury2
@StarFury2 Жыл бұрын
Thank you clear code for showing us camera concepts! I learned a lot from your videos. But some implementations here seems unnecessarily complicated, for example this method def my_mouse_control(self): mx, my = pygame.mouse.get_pos() if mx < self.camera_rect.left: self.offset.x -= 10 if mx > self.camera_rect.right: self.offset.x += 10 if my < self.camera_rect.top: self.offset.y -= 10 if my > self.camera_rect.bottom: self.offset.y += 10 replaces all 30+ lines of code in the mouse_control method, while working much better in my opinion. Another problem is zoom implementation, while it works, it's completely destroys FPS (from 300 to 30 and lower) making it completely unusable in practice. While this is probably due to pygame's lack of hardware acceleration, moving creation of scaled_surf out of the custom_draw loop and calling it only when mouse wheel is used helps to some degree.
@garainfamily7431
@garainfamily7431 2 жыл бұрын
I think you are underrated but your game are very awesome!
@maestroroshi1627
@maestroroshi1627 2 жыл бұрын
Amazing content!
@rudomir-__-2929
@rudomir-__-2929 4 ай бұрын
And again really helpful, thanks
@jagsingh121
@jagsingh121 Жыл бұрын
Amazing as always. Would be great if you can extend this to include a function that translates coordinates (e.g. mouse position) from screen to ground coordinates. This would really open up game world interactivity. It is not obvious how to do this if the zoom scale factor is not <a href="#" class="seekto" data-time="61">1:1</a>.
@paulinaceze4935
@paulinaceze4935 2 жыл бұрын
Thank you!! 🤗
@zarkive43
@zarkive43 2 жыл бұрын
Thx for the tutorial
@MustafaTuncay..
@MustafaTuncay.. 2 жыл бұрын
Hello! Is it possible to make a video about the plan-making before the game. You have many functions and classes in your games but how do you plan all this? It will be perfect if you can mention these in a video. Thanks a lot for the wonderful videos on pygame. All best :)
@torex.
@torex. Жыл бұрын
Thank you you helped to me
@pol_gd
@pol_gd 2 жыл бұрын
Hey, thanks for the awesome video, very useful. I do have a question however, my framerate dives down completely when zooming. It doesn't really seems to appear in your video but basically each zoom level divide my frame rate by two. And it is already kinda low to begin with. I was wondering if I've missed a huge piece of information during the video or if it's normal ? Edit: It seems that the pygame.transform.scale operation is really heavy for the CPU. Edit2: the memory usage seems to be also off the charts, with more than one gigabyte at a high zoom level. It's not a leak, as it decrease with the zoom. So yeah, it seems that in the end using a scaled surface create this massive texture that PyGame cannot handle very well at some point
@StarFury2
@StarFury2 Жыл бұрын
Yes, this zoom implementation completely destroys FPS. Moving creation of scaled_surf out of the custom_draw (so that it's not created on every frame, but only when mouse wheel is used) helps a little bit. The main problem here is Pygame's lack of supoort for hardware scaling I think, and something like Pyglet with it's OpenGL support would probably work much better. I love pygame, but the more I learn it, the more hopless it seems for any practical use except learning.
@vk2172
@vk2172 2 жыл бұрын
Absolute legend x
@ciscornBIG
@ciscornBIG 2 жыл бұрын
Elite content.
@suhasjaladi5098
@suhasjaladi5098 2 жыл бұрын
You are the pygame GOAT
@vodkawhisperer3923
@vodkawhisperer3923 Жыл бұрын
you are a GODSEND
@jindolipundit351
@jindolipundit351 Жыл бұрын
Also I love your videos!!
@SwiCyc
@SwiCyc 2 жыл бұрын
Thank you sooo much! I'm gonna combine this with the zelda tutorial!
@tacticcoconut
@tacticcoconut 2 жыл бұрын
Hey @Clear Code, What about a camera tracking multiple objects? A camera that zooms in and out and moves based on the selected objects in the scene? similar to smash bro camera setup?
@101touchapps
@101touchapps Жыл бұрын
nice!
@raghavsood28
@raghavsood28 2 жыл бұрын
Can you make a tutorial for particle effects in pygame? Like, particle effects whenever you hit something or jump in a platformer.
@Anakin_Skywalker_pasx9CUdxkPOW
@Anakin_Skywalker_pasx9CUdxkPOW 10 ай бұрын
For the zoom, do you know how to have multiple images for 1 sprite display because it doesn't work with lists as far as I'm aware
@necote8544
@necote8544 2 жыл бұрын
Nice, bro!
@nguyenquangchi
@nguyenquangchi Жыл бұрын
nice video
@baymax8386
@baymax8386 Жыл бұрын
good vid
@estebancortez5613
@estebancortez5613 Жыл бұрын
thank you!!! video liked and u got a well deserved sub from me!!!!
@at0mica924
@at0mica924 6 ай бұрын
Hey I’ve encountered an issue with mine is ive tried to do this without the use of groups of for a school project, for the center camere (<a href="#" class="seekto" data-time="1151">19:11</a>) I have an issue where I put my player object through a sprite list, then made a for loop similar to yours where I run thru it, but when I blit the image onto the screen it blits an image of the sprite but not the object itself so when I call its other functions it creates a whole different entity, any help would be appreciated
@atomfighter4726
@atomfighter4726 2 жыл бұрын
Great tutorials. I had this error come up here is my fix. ERROR MESSAGE: TypeError: integer argument expected, got float` FILE: camera.py ERROR: (approx. line 171) scaled_surf = pygame.transform.scale(self.internal_surf,self.internal_surface_size_vector * self.zoom_scale) ERROR FIX: scaled_x = int(self.internal_surface_size_vector.x*self.zoom_scale) scaled_y = int(self.internal_surface_size_vector.y*self.zoom_scale) scaled_surf = pygame.transform.scale(self.internal_surf, (scaled_x, scaled_y))
@pranavnyavanandi9710
@pranavnyavanandi9710 2 жыл бұрын
@Dr Kayin Miller Or you can directly use the floor division operator //.
@alboris8203
@alboris8203 3 ай бұрын
how did you make the shadow/lighting system from the thumbnail? would love a tutorial
@BorziBandz
@BorziBandz 2 ай бұрын
i would like to know this!!
@jk-gn2fu
@jk-gn2fu 2 жыл бұрын
Please do simple 2d lighting and basic shaders!!
@johnstarfire
@johnstarfire 2 жыл бұрын
<a href="#" class="seekto" data-time="750">12:30</a> = genial
@KiraAylaria
@KiraAylaria 2 жыл бұрын
Will you make a Tutorial on how to transition between maps in a top down game like in zelda with pygame? I cannot find a good tutorial for that.
@pranavnyavanandi9710
@pranavnyavanandi9710 2 жыл бұрын
Even your file explorer has a nice theme. How did you do that?
@Araxdied
@Araxdied 2 жыл бұрын
Mmm... I have a question. What's the best method to check if a sprite is inside the camera view? For example, I want to update a sprite animation and to check if there are collisions only if the sprite is visible, but I find it a bit hard to implement the code in a template like yours. How can I do it?
@ClearCode
@ClearCode 2 жыл бұрын
create another rect with the topleft being on the offset point and with the width and height of the window? Anything inside of that rect should be in view.
@Araxdied
@Araxdied 2 жыл бұрын
@@ClearCode Well, thank you very much! Now it works perfectly
@seargentyeet880
@seargentyeet880 Жыл бұрын
For the player center camera, I dont understand what the "group" argument in the player class does and what putting the group argument in super().__init__(super) does or how these 2 things are needed to like connect the player sprite class with the camera group sprite class. I would greatly appreciate it if someone could explain this to me? Thanks in advance :D
@mdshohidulalam5394
@mdshohidulalam5394 2 жыл бұрын
Hey what code editor do you use?
@guillermomolins3683
@guillermomolins3683 Жыл бұрын
Great video! Super helpful! For anyone having issues with render order, I recommend inheriting pygame.sprite.LayeredUpdates for CameraGroup since this allows you to draw based on the "layer" property from the Sprite class. Then, in the lambda function you sort by layer and then by the y coordinate.
@billielynploof9317
@billielynploof9317 Жыл бұрын
These videos are so helpful. Thank you for all your hard work! I'm trying to add an npc to this so that when the player collides with the npc it prints something to the terminal collideworked = collide_rect(player, bart) print(collideworked) if collide == True: print("you walked into an npc") I'm struggling to connect these two sprites because of the camera changes I have tried finding the player's topleft and bottom right and matching those coordinates to the npc but for some reason those coordinates are totally different and I think it's because player and the npc are in different spritegroups? So using the above code just keeps saying Error: global name 'collide_rect' is not defined I'm using pygame 1.9.2 and python 3.2 because I have a very old pc so maybe collide is not implemented yet? Any help you send would be so kind and I would be very thankful to anyone with ideas that could help me Billie Lyn
@ClearCode
@ClearCode Жыл бұрын
You should update your python and pygame, it isn't going to be more hardware intensive. Besides that, pygame 2 only added support for more hardware but all the basic methods have been around for about 20 years so that won't be your issue. I think the issue in your code is that you are calling get_rect on something that isn't a rect.
@billielynploof9317
@billielynploof9317 Жыл бұрын
@@ClearCode Thank you for all the volunteer work you are doing to make education accessible to so many people
@vaibhav6982
@vaibhav6982 2 жыл бұрын
In line 58, you are creating a Tree object and passing it the cameragroup as argument but ow is that adding the object to the group there is no 'add' method. Is there something being done when you intialize the Sprite clas with the cameragroup as an argument?
@thomasangelo8009
@thomasangelo8009 4 ай бұрын
good video but there is something unclear for me in the player center camera, when the player moves for example to the right are we only shifting the ground and the trees positions to the left on the xy axis, or are we shifting the whole xy axis, for example lets suppose the screen width is 110 and the player is moving from 110 to 111 , if the ground and the trees are the only things moving then the they will be shifted to the left and the player will get out of the screen because his new position is 112 and the xy axis and the screen are fixed but if the whole xy axis is moving to the left then the player won't get out of screen because the xy axis was shifted to the left and thus the point 112 will be inside the screen
@dominiknowec9837
@dominiknowec9837 10 ай бұрын
a question: Can we still use **kwargs for attribute inheritance along with *groups for assigning to groups in the same class inherited from Sprite?
@GCKteamKrispy
@GCKteamKrispy Жыл бұрын
Hey guys, have a question. How can I make player center camera smoother? It's kinda choppy
@aidanlee7452
@aidanlee7452 2 жыл бұрын
I've been trying to figure out how to create a game engine using pygame.. trying to find videos but there are practically none out there .. and I don't know where to start I feel like with your style of tutorials you could easily explain and even make some what of a series on it .. a pygame 2D game engine
@Zac8668
@Zac8668 2 жыл бұрын
yeah thats not gonna happen i think, making a game engine is kinda, not a good content for a video imo, he might do it, but you could just get all his tutorials about movement, camera, etc, and put it all together
@daon23
@daon23 2 жыл бұрын
video suggestion, a pico-8 game? maybe.
@vezpro6691
@vezpro6691 Жыл бұрын
I was so triggered when you sorted by centery while you could do bottom, bottom is so much better
@ogif2
@ogif2 2 жыл бұрын
Could you do a pygame tutorial with rigg?
@HeroHearth
@HeroHearth Жыл бұрын
what theme are you using?
@shalevforfor5550
@shalevforfor5550 6 ай бұрын
<a href="#" class="seekto" data-time="1080">18:00</a> so camera is just not the player move , all the objects move to the opesite right ?
@shihyuehjan3835
@shihyuehjan3835 Жыл бұрын
for sprite in sorted(self.sprites(), key = lambda sprite: sprite.rect.centery): how this code work?
@shanealma612
@shanealma612 2 жыл бұрын
Hello, great video, can i export to Android?
@Araxdied
@Araxdied 2 жыл бұрын
I love you.
@nononononononononono2045
@nononononononononono2045 2 жыл бұрын
how about menus or eq?
@seizera7586
@seizera7586 2 жыл бұрын
Isnt your icon just the snapped flutter icon?
@parultandon8566
@parultandon8566 2 жыл бұрын
How many years of experience do you have?
@SkyFly19853
@SkyFly19853 2 жыл бұрын
Wow...
@jindolipundit351
@jindolipundit351 Жыл бұрын
can you send the code for just the player center camera please
@n0rmaLman
@n0rmaLman 3 ай бұрын
Why is the drawing of box camera rect so strange? Why does it behave like that?
@tikka6554
@tikka6554 2 жыл бұрын
Are you using vim?
@dominiknowec9837
@dominiknowec9837 10 ай бұрын
how does this apply to multiplayer games?
@PVPSMILE
@PVPSMILE 2 жыл бұрын
Where can I find code of this game?
@omergatenio6802
@omergatenio6802 2 жыл бұрын
Your tutorials are amazing!! You should make a Udemy course about pygame, I'll buy it for sure 😃
@akash0156
@akash0156 2 жыл бұрын
Question is python really good for creating 2d game?
@heavymetal1ization
@heavymetal1ization 2 жыл бұрын
I don't know how experienced you are but the short answer is no. Python is not meant to be used to create games, although it is a lot of fun.
@harshalpatel6255
@harshalpatel6255 Жыл бұрын
+sub, workis
@karejhon6140
@karejhon6140 2 жыл бұрын
Hello i am start saying thanks for you work creating this videos :D i am Spanish speaker and i am want translate your videos to spanish for help more people ¿I can do that? Sorry for errors in the comment, i am only know the basic of english
@ClearCode
@ClearCode 2 жыл бұрын
Of course :)
@karejhon6140
@karejhon6140 2 жыл бұрын
@@ClearCode nice thanks bro :D
@panther9358
@panther9358 Жыл бұрын
I’m overwheld it’s soooo much
@embodythelogos
@embodythelogos Жыл бұрын
Hi, can you add a MIT license to your Github repository? I want to use your code as a reference for a part of the project which I will use for commercial purpose. I guess making the tutorial means you want me to learn from your code and make modifications to it to fit my needs. However, I still want to make sure; I don't want to deal with any legal issues. Thank you!!
@ClearCode
@ClearCode Жыл бұрын
Oh sorry, will add it but all of it is published under a CC0 license. You can use it for any purpose even without attributions :)
@notenlish
@notenlish 2 жыл бұрын
<a href="#" class="seekto" data-time="68">1:08</a>:57
@0rd3r
@0rd3r Жыл бұрын
u make very good videos, but (i think) you dont follow some rules of pep still tho keep going :) and please ignore my bad english
@zaaffe24bs16
@zaaffe24bs16 2 жыл бұрын
are you german?
@boyzaa9531
@boyzaa9531 Жыл бұрын
anybody's, pls rember that! i wish all of you the best in your future endeavours and hope tNice tutorials year will treat us better
@aMyst_1
@aMyst_1 2 жыл бұрын
:)
@odams
@odams 2 жыл бұрын
YAY I AM THE 1K's VIEWER
@damianworth4562
@damianworth4562 Жыл бұрын
U Irish or Scottish mate
@doublegameplaysandscriptin977
@doublegameplaysandscriptin977 Жыл бұрын
trying to be a stick in the mud lol, just trying to help.
@xskerrittx1
@xskerrittx1 2 жыл бұрын
Your code logic wise works amazing, but your lack of PEP-8 or any formatting rules kills me! Each comma should have a space after it, and in function calls, the key word arguments should not have a space around the equals symbol!
@LuisPereira-bn8jq
@LuisPereira-bn8jq 2 жыл бұрын
Oh yes, because managing white space is truly the essence of programming. In most scenarios PEP-8 will result only in marginal improvements to readability. Having an add-on that fixes formatting is fine, but no thinking human being should be wasting their mental energy on something as sterile as PEP-8.
@xskerrittx1
@xskerrittx1 2 жыл бұрын
@@LuisPereira-bn8jq Bro why you so angry, I literally said everything works great, it would just be nice to follow convention. So mad for no reason lmao
@LuisPereira-bn8jq
@LuisPereira-bn8jq 2 жыл бұрын
@@xskerrittx1 Actually, bro, you whined about how much the lack of PEP-8 was "killing you". Rather than being entitled, bro, actually think about what you are doing: asking someone else to do a bunch of extra work just to follow a convention with zero practical benefit.
@xskerrittx1
@xskerrittx1 2 жыл бұрын
@@LuisPereira-bn8jq Cry
@LuisPereira-bn8jq
@LuisPereira-bn8jq 2 жыл бұрын
@@xskerrittx1 Nah, I'll leave that to you. I've patiently explained why your "suggestion" is actually harmful. Up to you whether you accept reality or not.
@quentindaloz3855
@quentindaloz3855 2 ай бұрын
pas assez fort le son. rebois tes reglages et apres tu pourras coder. byer.
@GustonClips
@GustonClips 8 ай бұрын
i don't know if am the only person that complains about this but the videos are not very clear
@tonverandertsflotenmonitor5038
@tonverandertsflotenmonitor5038 Жыл бұрын
To whom who want to download this. Follow all the steps shown in video, It works Thank you creator
Breakout in python
3:21:21
Clear Code
Рет қаралды 59 М.
How to Code (almost) Any Feature
9:48
DaFluffyPotato
Рет қаралды 653 М.
A pack of chips with a surprise 🤣😍❤️ #demariki
00:14
Demariki
Рет қаралды 47 МЛН
1❤️#thankyou #shorts
00:21
あみか部
Рет қаралды 88 МЛН
Haha😂 Power💪 #trending #funny #viral #shorts
00:18
Reaction Station TV
Рет қаралды 9 МЛН
Learning pygame by creating Snake [python tutorial]
2:05:00
Clear Code
Рет қаралды 341 М.
Multiple Scenes in Pygame Tutorial (Gamestates)
15:46
Coding with Sphere
Рет қаралды 10 М.
I made Games with Python for 10 Years...
28:52
DaFluffyPotato
Рет қаралды 261 М.
Understanding framerate independence and deltatime
29:22
Clear Code
Рет қаралды 38 М.
2 Python Developers VS $1000
15:04
PolyMars
Рет қаралды 1,7 МЛН
Reverse Engineering Game Code from the Neutral Zone
40:59
Retro Game Mechanics Explained
Рет қаралды 537 М.
Creating Minecraft in Python [with the Ursina Engine]
48:54
Clear Code
Рет қаралды 1,7 МЛН
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Coding With Russ
Рет қаралды 843 М.
I Made a Neural Network with just Redstone!
17:23
mattbatwings
Рет қаралды 622 М.