pygame-surface

How to draw sprite on a sprite so that both of them will be seen in pygame [duplicate]

落花浮王杯 提交于 2021-02-10 14:23:20
问题 This question already has answers here : How do I blit a PNG with some transparency onto a surface in Pygame? [duplicate] (4 answers) Closed 24 days ago . I have two sprites one of them is a tank sprite the other is a protection sprite. I want to draw the protection sprite on the tank sprite. The images of the sprites are as follows: When I draw the protection sprite on the tank sprite, the result is the following: Center of the protection sprite is empty (according to photoshop, I checked

PyGame Invalid Position For Blit

不羁岁月 提交于 2021-02-05 09:39:18
问题 I am creating a small level designer in Python (using PyGame). The program is supposed to just let you place down an image, change between images, export to a PNG file, and export image path and coordinates to where it was place in a text document. I have gotten all of these components to work, but I am stuck with one last component, and that is reading the text document back into PyGame, and re-placing all of the images in the correct places with the correct sprites. The way that I have it

how rotate the images with keyboards? [duplicate]

一笑奈何 提交于 2021-02-05 09:12:54
问题 This question already has answers here : How can I make a sprite move when key is held down [duplicate] (3 answers) How do I rotate an image around its center using Pygame? (6 answers) Closed 3 months ago . img1 = pygame.image.load(r"C:\Users\ga-sa\Downloads\As.png") img2 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsXOR.png") img3 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsNOT.png") img4 = pygame.image.load(r"C:\Users\ga-sa\Downloads\AssetsAND.png") background = pygame.image

Zooming in and out of a PyGame window with all objects still in place

无人久伴 提交于 2021-02-05 07:58:47
问题 I am having an issue with PyGame i can't resolve. So: my idea is that I have a map I can zoom in/out on. zooming in works fine. But zooming out shows that the rest of the picture got deleted and only the part of the image that was previously visible on the window exists now. This is my code: import pygame from pygame.locals import * import os class App: def __init__(self): self.running = True self.size = (800,600) #create window self.window = pygame.display.set_mode(self.size, pygame

How do I pass a rect into pygame.display.update() to update a specific area of the window?

半世苍凉 提交于 2021-02-05 07:02:26
问题 On the documentation page for pygame.display.update() , it says you can pass a rect into the method to update part of the screen. However, all of the examples I see just pass an existing rect from an image or shape in the program. How can I tell it to update an area on the screen directly? For example, when drawing a rectangle, I could use a rect argument of (100,200,30,40) . This would draw a rectangle with a top at 200, a left at 100, a width of 30, and a height of 40. How can I pass a

How to save object using pygame.Surfaces to file using pickle

别来无恙 提交于 2021-02-05 06:42:11
问题 If I have created my own class which has some attributes that are pygame.Surfaces and I would like to save this object to a file, how can I do this as an error occurs when I try. The class which I have created is an object which is essentially the following (Item class is included because the player has items which have attributes that are pygame.Surfaces): class Item: def __init__(self,name,icon): self.name = name self.icon = pygame.image.load(icon) class Player(pygame.Sprite): def __init__

How could I optimise this simple python pygame code

为君一笑 提交于 2021-02-04 08:14:08
问题 I've been set a challenge to make a game using pygame ( I am making snake so it should be easy... but I've never used pygame) so using a more efficient language isn't an option.So my question is that I updating the snake grid is too slow and I'm not experienced enough in pygame to fix this, can anyone who is help.Also as a note if I only fill the grid it doesn't clear behind the Snake. Using python 3.8 import pygame import time import random pygame.init() display_width = 800 display_height =

Why my pygame game with a tiled map is lagging?

时光怂恿深爱的人放手 提交于 2021-02-04 08:07:33
问题 I just started pygame and I started coding a little game, but when I put the code for the tiled map my game lagged! I don't understand why so I ask you. my code: import pygame from player import Player from level import Level clock = pygame.time.Clock() from pygame.locals import * pygame.init() WIDHT = 1024 HEIGHT = 768 MAP_FILE = "niveau.txt" pygame.display.set_caption("TEST") screen = pygame.display.set_mode((WIDHT, HEIGHT)) player = Player() moving_right = False moving_left = False moving

Why my pygame game with a tiled map is lagging?

坚强是说给别人听的谎言 提交于 2021-02-04 08:06:53
问题 I just started pygame and I started coding a little game, but when I put the code for the tiled map my game lagged! I don't understand why so I ask you. my code: import pygame from player import Player from level import Level clock = pygame.time.Clock() from pygame.locals import * pygame.init() WIDHT = 1024 HEIGHT = 768 MAP_FILE = "niveau.txt" pygame.display.set_caption("TEST") screen = pygame.display.set_mode((WIDHT, HEIGHT)) player = Player() moving_right = False moving_left = False moving

PYGAME - Move Character with Vector

为君一笑 提交于 2021-02-04 07:27:32
问题 I am teaching myself pygame and am looking at making my character able to rotate and then move in the direction they are facing. I can do the rotation but cannot get the character to move in the direction the image is then facing. The code is on Trinket HERE class Bob(pygame.sprite.Sprite): def __init__(self, color , height , width): super().__init__() self.image = pygame.Surface([width , height]) self.image.fill(BLACK) self.image.set_colorkey(BLACK) #Loading the image for the character self