Pygame Camera - Pygame RPG Tutorial #8

  Рет қаралды 14,077

ShawCode

ShawCode

Күн бұрын

Пікірлер: 68
@celloj3703
@celloj3703 2 жыл бұрын
you are the Bob Ross of programming and I live for it
@ShawCode
@ShawCode 2 жыл бұрын
Lmao, unfortunately I'm not rocking the afro anymore tho ;(
@katrinabest3129
@katrinabest3129 3 жыл бұрын
Hi Caleb, I am a recent subscriber and a third year uni student studying stats, but I've really enjoyed the way that you've described using Pygame. I am building a game personally and I just wanted to mention a bug and a fix that I found regarding colliding with the border blocks. With the current code, if you try going out of bounds, the character stays but the camera will move, hence unfortunately trying to recenter your camera. It's a small fix, but if you also change all of the sprites movement to counteract the movement of the camera, then it will not move at all, just like the player. Here is the code that I have found works (I placed it in Player.collide_blocks) but I hope this helps! if self.x_change > 0: self.rect.x = hits[0].rect.left - self.rect.width for sprite in self.game.all_sprites: sprite.rect.x += PLAYER_SPEED if self.x_change < 0: self.rect.x = hits[0].rect.right for sprite in self.game.all_sprites: sprite.rect.x -= PLAYER_SPEED
@ShawCode
@ShawCode 3 жыл бұрын
Thanks for pointing this out, I will definitely add this in the next tutorial!
@MsLorrainia
@MsLorrainia 3 жыл бұрын
The fix worked perfect! Thank you! (for those who are still having issues, make sure you place the code ShawCode showed first, then add the same code as shown above in the collide_blocks. Don't forget to add to the y coords too : def collide_blocks(self, direction): if direction == 'x': hits = pygame.sprite.spritecollide(self, self.game.blocks, False) if hits: if self.x_change > 0: for sprite in self.game.all_sprites: sprite.rect.x += PLAYER_SPEED self.rect.x = hits[0].rect.left - self.rect.width if self.x_change < 0: for sprite in self.game.all_sprites: sprite.rect.x -= PLAYER_SPEED self.rect.x = hits[0].rect.right if direction == 'y': hits = pygame.sprite.spritecollide(self, self.game.blocks, False) if hits: if self.y_change > 0: for sprite in self.game.all_sprites: sprite.rect.y += PLAYER_SPEED self.rect.y = hits[0].rect.top - self.rect.height if self.y_change < 0: for sprite in self.game.all_sprites: sprite.rect.y -= PLAYER_SPEED self.rect.y = hits[0].rect.bottom
@sndksnebfuiw
@sndksnebfuiw 10 ай бұрын
@@MsLorrainia Bro, thanks for the help with the camera. Now she doesn't fly away XD. But I got another one, when I rearrange the player's spawn point, the camera remains in the previous place, and the player is at the spawn point. What to do? How do I focus on the player?
@alicemystery5520
@alicemystery5520 3 жыл бұрын
I am surprised at how much this is helping me understand how to program in python. Along with separating the code into various files and folders. Which almost none of the tutorials explain like your series is doing. Thanks man!
@ShawCode
@ShawCode 3 жыл бұрын
Glad it helped!
@tomasdelpino932
@tomasdelpino932 9 ай бұрын
What I have done to make the camera not move in case of a collision is the following: Inside the collide_blocks method create an else statement where if it doesnt hit and x_change > 0 or whichever the case is, it calls a move_camera method, and within that method you write the for loop that's in this video. Do this for all 4 directions
@МастерОтступник
@МастерОтступник 3 жыл бұрын
Finally U have done the tilemap game! Наконец-то ты закончил тайлмап игру! 👏🏼from empty to game из пустоты в игру
@ShawCode
@ShawCode 3 жыл бұрын
:D
@beronicous7086
@beronicous7086 2 жыл бұрын
This is the most simple and best tutorial about cameras! How do you make the map bigger, though?
@ShawCode
@ShawCode 2 жыл бұрын
Thanks! To increase the map size, you just add more rows and columns to your tilemap list.
@jademendes5572
@jademendes5572 Жыл бұрын
Thank you for coming up with such a simple solution for the camera!! This will help me greatly
@ShawCode
@ShawCode Жыл бұрын
Glad I could help!
@hhh-yh8wn
@hhh-yh8wn 10 ай бұрын
I first tried working with offsets when you create a vector2() and then subtract it from the current pos and it becomes the offset_pos and then you have to center the player. And then you find out that you can not interact with objects because their possitions remained default (kinda). I am a begginer and that seemed a bit complex this code of yours is 10 times simpler and I will never get confused
@s.dh29
@s.dh29 3 жыл бұрын
Ayyyy, your back! Loved this tutorial as much I loved all ur other videos :)
@ShawCode
@ShawCode 3 жыл бұрын
Thanks :D
@abd_cheese7353
@abd_cheese7353 2 жыл бұрын
Seems great, though im wondering if this affects performance very much? Or if there is a more optimized way to do this?
@ShawCode
@ShawCode 2 жыл бұрын
Good question - it may have a slight impact on performance, but this is my solution to creating a camera in pygame. Someone will probably have a better way of doing it, but unfortunately unlike other game engines there isn't a simple way to add a real camera.
@abd_cheese7353
@abd_cheese7353 2 жыл бұрын
@@ShawCode I see, thanks for the reply
@jakecastle4426
@jakecastle4426 3 жыл бұрын
Hey, so i toyed with the code i was left with a while back (you may remember me), and got shooting and walking around with following camera, finally figured out how to write and implement A* Pathfinding (the whole game is passed 1000 lines at the moment). It needs a rewrite, cuz ive learned so much since i started.. So with your help, im rewriting a new game from scratch because i need the core to work differently. Im confident i can do it too, thanks to you.
@ShawCode
@ShawCode 3 жыл бұрын
Nice job! Adding pathfinding to the enemies is really quite complicated, well done!
@yousefangox3022
@yousefangox3022 3 жыл бұрын
you're tutorials are nice when you collide with a block and hold down the arrow key the camera keep moving if there's a solution for that it will be awesome
@ShawCode
@ShawCode 3 жыл бұрын
I gave a fix to that in my latest video!
@itschris1881
@itschris1881 3 жыл бұрын
very very good thanks so much dear bro
@ShawCode
@ShawCode 3 жыл бұрын
Thanks!
@itschris1881
@itschris1881 3 жыл бұрын
@@ShawCode your welcome bro
@MyriadColorsCM
@MyriadColorsCM Жыл бұрын
Is there a way of making the "camera" no longer move if your character collide? I tried setting up a collide detection check but it didnt work.
@simplyhypixel6876
@simplyhypixel6876 10 ай бұрын
This is probably a somewhat brute force method but you can try doing something like making a list of all the rects that the player can collide with and then put that in a for loop and check if the player.rect is colliding with anything at a given moment and then go ahead and put that if statement above the camera movement logic
@MsLorrainia
@MsLorrainia 3 жыл бұрын
So, I noticed that when I add this 'camera' functionality, if I hit a wall, and keep running against it, the camera keeps going until there's nothing on the screen. Is there a way to stop the camera from continuing to scroll off map?
@MsLorrainia
@MsLorrainia 3 жыл бұрын
Oops! I saw someone asked this already! look forward to the fix!
@ShawCode
@ShawCode 3 жыл бұрын
The next tutorial will show you how to do this!
@edgar123456789P
@edgar123456789P 3 жыл бұрын
hey whats up shawcode, thanks for the video, I had a quick question and was hoping you could help, once we collide with a wall, the camera keeps going on its own as long as we keep pressing against the wall, is there a way to stop that?
@ShawCode
@ShawCode 3 жыл бұрын
I will be fixing this in a future tutorial - it is quite an easy fix!
@markbenjamin6299
@markbenjamin6299 3 жыл бұрын
Is it possible to use a bigger map than the window and have more of it show up as the camera moves instead of black?
@ShawCode
@ShawCode 3 жыл бұрын
Sure, you just increase the size of the tile map list!
@aminezouaoui5834
@aminezouaoui5834 3 жыл бұрын
How can we do that using only the mouse and without any Sprite ?? I mean in case that you have a Map and you want to scroll all over it with a camera following ur mouse cursor . It will be really amazing if you help me with that it's for a project !!
@ShawCode
@ShawCode 3 жыл бұрын
Did you manage to figure this out with help the discord server? If you still need help, let me know!
@aminezouaoui5834
@aminezouaoui5834 3 жыл бұрын
@@ShawCode I still have a problem , Didn't get how to redraw the blac background after redrawing my tileMap.
@lpmittheo9904
@lpmittheo9904 2 жыл бұрын
could you please make a tutorial how to stop the camera if the player colides with a rock
@ShawCode
@ShawCode 2 жыл бұрын
Yes, I fix this bug in the final tutorial!
@charchitdahiya986
@charchitdahiya986 3 жыл бұрын
Will there be levels in the game
@ShawCode
@ShawCode 3 жыл бұрын
I won't be adding them in this series, but all you will have to do is create more tilemaps, and draw a different tilemap onto the screen for a new level!
@sahilakhtar8815
@sahilakhtar8815 3 жыл бұрын
Hey Show, Just one question from where did you learn Python?
@ShawCode
@ShawCode 3 жыл бұрын
From internet tutorials like these!
@sahilakhtar8815
@sahilakhtar8815 3 жыл бұрын
@@ShawCode nice brother
@DopeAK7
@DopeAK7 2 жыл бұрын
For me, the for loop in the movement method moves the enemies with the player too, how do i fix this?
@ShawCode
@ShawCode 2 жыл бұрын
Could you copy and paste all your code for me please?
@DopeAK7
@DopeAK7 2 жыл бұрын
by copy and paste, what do you mean because I dont think my code can fit here
@ShawCode
@ShawCode 2 жыл бұрын
@@DopeAK7 Could you please copy and paste each file as a separate reply? It should be able to fit that way.
@kuchtwotimes
@kuchtwotimes 3 жыл бұрын
hey im having an issue where in my tilemap, if I put P, there will be two instances of my character. and if my tilemap doesnt have P at all, a character in the top left of the screen will spawn. i dont know how to get rid of the one that isnt on the tilemap.
@ShawCode
@ShawCode 3 жыл бұрын
Please could you copy and paste your main.py for me? I think you are creating another instance of the Player class somewhere in your code.
@kuchtwotimes
@kuchtwotimes 3 жыл бұрын
@@ShawCode I figured it out! Thank you though, you're right. In the main.py I never ended up deleting the self.player = Player(self, 1, 2). Got it now! I'm impressed you keep up with the comments. Thanks a lot.
@ShawCode
@ShawCode 3 жыл бұрын
@@kuchtwotimes Nice job!
@pythonista_333
@pythonista_333 3 жыл бұрын
at the end of the video i've noticed that the camera still moves when the player collides with the wall
@ShawCode
@ShawCode 3 жыл бұрын
Thanks for pointing this out, I will be fixing it in one of the next tutorials!
@clarkkellis5548
@clarkkellis5548 3 жыл бұрын
You should do some research on the pygame subset for Android because with it you can turn your pygame into an Android mobile game. I would appreciate it if you could figure it out and make a tutorial series on it because I can't find much about it on KZbin.
@ShawCode
@ShawCode 3 жыл бұрын
Thanks for the idea, it looks interesting!
@thequocnguyen1341
@thequocnguyen1341 3 жыл бұрын
thanks you. I learn many thing from you. Can you help me, i have many pdf file, i want to convert them to latex, but i can't do it.
@ShawCode
@ShawCode 3 жыл бұрын
Thanks! Sorry, I don't know much about latex.
@thequocnguyen1341
@thequocnguyen1341 3 жыл бұрын
@@ShawCode thank you for reply, your video is helpful with me ! (my english is not good)
@akashramgir4866
@akashramgir4866 3 жыл бұрын
i want to learn logic building in programming how ?
@ShawCode
@ShawCode 3 жыл бұрын
It just takes lots of practice!
Pygame Menu / Intro Screen - Pygame RPG Tutorial #9
11:37
ShawCode
Рет қаралды 14 М.
Cameras in Pygame
1:13:21
Clear Code
Рет қаралды 122 М.
Walking on LEGO Be Like... #shorts #mingweirocks
00:41
mingweirocks
Рет қаралды 6 МЛН
Who's spending her birthday with Harley Quinn on halloween?#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 20 МЛН
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 71 МЛН
Pygame Images with Sprite Sheet - Pygame RPG Tutorial #4
12:15
Pygame Collision Detection - Pygame RPG Tutorial #5
7:19
ShawCode
Рет қаралды 15 М.
C++ Developer Learns Python
9:26
PolyMars
Рет қаралды 2,7 МЛН
Pygame RPG Tutorial #1 - Pygame Tutorial
19:31
ShawCode
Рет қаралды 98 М.
Pygame Tilemap - Pygame RPG Tutorial #3
12:33
ShawCode
Рет қаралды 22 М.
Pygame Game Over Screen - Pygame RPG Tutorial #10
6:42
ShawCode
Рет қаралды 9 М.
Pygame Attacks - Pygame RPG Tutorial #11
12:03
ShawCode
Рет қаралды 10 М.
Walking on LEGO Be Like... #shorts #mingweirocks
00:41
mingweirocks
Рет қаралды 6 МЛН