Today, we are going to learn about Controlling images in pygame! So let's begin, first I'm going to talk about the "pygame.blit". So what is its use? So it is for blit or showing the image on a screen.
So I use "screen. blit" to draw this dot on the screen. I could've used the draw function. But for the example, I downloaded the black dot and blited it. But there are some things that you have to do before using the blit function. You need to download the image that you want. Then put it in your python folder, in my case it was pythonProject6. Then I would put the black dot into the folder using ctrl + x or ctrl + c. You can change its name and all but you have to address it right. So it is "blakc_dot = pygame.image.load("c862a3c9ef219140fb365301f9ebbd50-black-dot")" then blit it using this code"screen.blit(black_dot, [pos_x, pos_y])" So that is it for the blit.
Let's learn about "pygame.transform" one of my favorites! So you can transform an image with that function. So let's see some examples. So one is extremely large, and one is extremely small. So it is very useful when an image is too big or small. So what do we use? We use "black_dot = pygame.transform.scale(black_dot, [scale_x, scale_y])" That is how you change the scale of a image in pygame. Now let's move on to the "pygame.transform.scale2x" which just is a way of 2X the image. They are the ones that I use most but I like the rotate too. "black_dot = pygame.transform.rotate(black_dot, vari)" and vari is just a variable that increases 1 every time. But if I run this, it will crash. So what do we do? I don't really have the solution for this, because I don't use rotate. But Clear Code has a really good tutorial about this. And that is all for today, and I will be back with a more helpful tutorial next time!
great
ReplyDeleteThanks
Delete