Informatics 9. Билингвальный учебник | страница 36



2. Which image formats are better to use, if you are picking out an image that will be transparent? Why?


Terminology

draw - сызу - рисовать

thickness - қалыңдық - толщина

key – батырма - клавиша

script – сценарий - сценарий

direction – бағыт - направление

transparent – мөлдір - прозрачный

pick out – таңдау - выбрать


4.4 UPLOADING CHARACTER

You will:

Upload ready characters for the game.


If you could be a video game character, who would you want to be and why?

Moving an Image

Now you will load a character image to your game. First of all, find and download any spaceship image. You can find a .gif or .png that you like with a white or black background.


Don’t use a .jpg.

To load the image you need the same type of command that you used with the background image. In this case, assume the file is saved as player.png.


player_img = pygame.image.load(“player.png”).convert()

Then, copy an image to the screen.


screen.blit(player_img, [x, y])

But now, if you run the code, you will get the space ship image with a solid white background. So when the image is drawn the program shows Figure 2.

You only want the space ship, not a rectangular background! But all images you can load are rectangles, so how to show only the part of the image you want?

The way to get around this is to tell the program to make one color “transparent” and not display. This can be done immediately after loading. The following makes the color WHITE transparent (assuming WHITE is already defined as a variable):

player_image.set_colorkey(WHITE)

This will work for most files ending in .gif and .png. (Figure 3)

This does not work well for most .jpg files (Figure 4).


Keep in mind

It is not possible to change a .jpg to another format just by renaming the file extension to .png. It is still a .jpg even if you call it something different. It requires conversion in a graphics program to change it to a different format.


Practice

Add some different types of enemies to your game, such as spacecraft, space rocks, and asteroids.


Literacy

1. What is the difference between adding a background image and character image?

2. Which image formats are better to use if you are picking out an image that will be transparent? Why?


Terminology

Assume - қабылдау - предполагать

immediately - дереу - немедленно

compression – қысу - сжатие

character – кейіпкер - персонаж

require – талап етеді - требовать

conversion – түрлендіру - преобразование


4.5 MOVING CHARACTERS