filterfert.blogg.se

Pygame image convert alpha
Pygame image convert alpha





pygame image convert alpha

pygame image convert alpha

(self.bullet2) class Bullet2(GameSprite): # Determine whether to exceed the screen if it is removed from the sprite group Create first hero and first bullet class Hero(GameSprite): Create background class class BackGround(GameSprite):ĩ. Create refresh screen refresh sprite group (including background picture, hero picture, bullet picture, zombie picture refresh and draw to the screen) def _update_sprites(self):ħ. If (, self.enemy_group, True, True):Įlif (, self.enemy_group, True, True):Įnemies = (self.hero, self.enemy_group, True)Įnemies2 = (self.eero, self.enemy_group, True)Ħ. Create a collision detection event (when a monster touches a character and exits the game) def _check_collide(self): Create a listening event (including the setting of the keyboard key to exit the window and launch bullets) def _handler_event(self):ĥ. Create a privatized spirit family def _create_sprites(self): Self.screen = _mode((SCREEN_RECT.width, SCREEN_RECT.height)) Create the PlaneGame class of the main game for initialization def _init_(self): Prepare the required picture material through ps processing.ġ. Define function (control player movement, bullet launch, monster random appearance)Ħ. Define the first and second heroes, bullets and monsters.ĥ. Define the PlaneGame class, Sprite class and background class of the main gameĤ.

#Pygame image convert alpha code#

Write the code and make the general windowģ. If one of the two players touches the zombie, it will be judged as a failure of the game. The number of zombies defeated by players is shown on the top of the game Player 2 controls the up and down left and right movement of characters by ↑ ↓ ←→ key, and the space bar is to launch bullets. To display what's been blitted to the screen you need to call () or ().Player 1 controls the up, down, left and right movement of the characters through the wa s d key, and the Q key is to fire bullets. It's possible to blit to other Surfaces than the screen.

pygame image convert alpha

The topleft of the Surface will be placed at the position. You also need to pass the position of the Surface, which should be a 2-element integer sequence or a Rect object. Blitting essentially means copying pixels from one Surface to another (the screen is a Surface as well). Surfaces needs to be blit to the screen in order to be able to display them. If your image contains transparency (alpha values) you just call the method convert_alpha() instead: my_image = (path_to_image).convert_alpha() This can be done by calling the Surface method convert(), like so: my_image = (path_to_image).convert() To improve performance it's usually wise to convert your image to the same pixel format as the screen. The path to the image can be relative or absolute. Creating a Surface with your image on is as easy as: my_image = (path_to_image) More often than not you'd like to use your own images in a game (called sprites). The argument color is a 3 or 4-element integer sequence or a pygame.Color object. You can use the pygame.draw module to draw shapes on the Surface, or fill it with a color by calling the Surface method fill(color). This is outside the scope of this example though. You can also pass additional arguments when creating a Surface to control bit depth, masks and additional features as per-pixel alpha and/or create the image in video memory. To create a Surface you need at minimum it's size, which is a 2-element integer sequence of width and height, representing the size in pixels. There are two ways to create a Surface: blank from scratch or by loading an image. A Surface is like a blank sheet of paper which contain colors or images. In pygame you usually use Surfaces to represent the appearance of objects, and Rectangles to represent their positions.







Pygame image convert alpha