pygame-surface

Slowly turning a rectangle in pygame

对着背影说爱祢 提交于 2019-12-25 05:27:27
问题 I have some code: mouseX, mouseY = pygame.mouse.get_pos() angle = math.degrees(math.atan2(mouseY - self.rect.centery, mouseX - self.rect.centerx)) rotated = pygame.transform.rotate(self.rect, -angle) self.rect = lol.get_rect() How should I modify this code to slowly turn the rectangle depending on the mouse angle (10deg/s etc.)? Edit: I want to rotate CLASS object (based on pygame.sprite.Sprite class) 回答1: Just don't rotate your image to the target angle, but only a little bit until you reach

Pygame creating surfaces

橙三吉。 提交于 2019-12-25 03:03:42
问题 Code: #!/usr/bin/python import pygame, time, sys, random, os from pygame.locals import * from time import gmtime, strftime pygame.init() w = 640 h = 400 screen = pygame.display.set_mode((w, h),RESIZABLE) clock = pygame.time.Clock() x = y = 100 def starting(): basicfont = pygame.font.SysFont(None, 48) text = basicfont.render('Starting...', True, (255, 255, 255), (0, 0, 255)) textrect = text.get_rect() textrect.centerx = screen.get_rect().centerx textrect.centery = screen.get_rect().centery

How do I blit an image to a surface in pygame that's the same size as a Rectangle

旧街凉风 提交于 2019-12-24 15:39:34
问题 I'm making a game with pygame and each Sprite has a rectangle and an image. How would I blit this image to a surface so that it's the same size as the rectangle? pygame.init() screen = pygame.display.set_mode((720, 480)) pygame.display.set_caption('My game') background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((250, 250, 250)) charRect = pygame.Rect((0,0),(10, 10)) print os.path.abspath("airbender.png") charImage = pygame.image.load(os.path.abspath(

How can I display strings on multiple lines?

六月ゝ 毕业季﹏ 提交于 2019-12-24 06:31:11
问题 I am writing a "High Scores" table window for my pygame. Currently I am unpickling a file and then breaking the tuples apart so I can display the player name on the left and the score on the right. However in the current configuration, all of the player names are stacked ontop of eachother and the same with the scores. I need to figure out how to display each new player name and score combo on a new line. I'm still pretty new to python (working with version 3), any help would be greatly

Pygame: Couldn't open file. Same directory

℡╲_俬逩灬. 提交于 2019-12-24 02:16:28
问题 I loaded 150 .tif images to a glob module and am currently unable to load them. I'm very new to programming so I imagine it's a dumb mistake I'm missing but I cant seem to figure it out. The is the code: import pygame, glob types= ('*.tif') artfile_names= [] for files in types: artfile_names.extend(glob.glob(files)) print(artfile_names) for artworks in artfile_names: pygame.image.load(str(artfile_names)) Thank you for any help! 回答1: The mistake is that your types variable is just a string

How do I add a line as a sprite in pygame?

拟墨画扇 提交于 2019-12-23 20:18:47
问题 I want to add a grid to my level that stays with the terrain and not the screen. The way I thought of doing it is to add all the lines that form the grid as sprites and move them with the terrain, but I can't figure out how to represent the line as an image. I tried to do this myself, but had no success. EDIT: Here's what I've tried class Grid(): def __init__(self): self.grid = pygame.Surface(size) self.grid.set_colorkey((0,0,0)) def draw(self): # DRAW TILE LINES -----------------------------

Will Pygame blit sprites with a rect outside the display

若如初见. 提交于 2019-12-12 21:12:55
问题 I'm currently working on a space exploration game in 2D top view. I have quite a few planets and since the map span is much greater than the display I end up with a lot of planet sprites lying outside the display area. At the moment I assume Pygame will not actually blit the sprite if they are not located in the display (as I understand it blitting and drawing to a surface slows things quite a lot) is that true ? Or would I need to add a condition to check if the sprite is located within the

How to use Python multiprocessing to prepare images for pygame

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 00:45:24
问题 I'm making a slideshow app with that oh-so-naught-ies pan and zoom effect. I'm using pygame. The main display is therefore realtime 30fps+, and I don't want it stuttering when it has to load a new image - this takes it over 1/30th of a second. So I wanted to use some parallel process to prepare the images and feed the main process with these objects, which are instances of a class. I've tried with threading and with multiprocess. Threading 'works' but it's still jumpy (I blame python) - the

How do I flip an image horizontally in pygame?

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:17:52
问题 This is in pygame. How do I flip an image (lets say an image of a pig looking to the right) to look to the left when I press the left arrow key, and stay like that even if I don't press any keys or if I press the up and down arrow keys. Then how do I switch it back again to look to the right when I press the right arrow key and make it stay like that even if I don't press any key or if I press the up and down arrow keys. I know I have to use pygame.transform.flip() . But, I don't know how to

Rotate an image in pygame using sprites

房东的猫 提交于 2019-12-11 06:35:36
问题 I am making a game in pygame and I wanted to rotate an image. pygame.transform.rotate kept increasing the images dimensions so I thought that maybe sprites could help me to rotate an image. But the problem is more complex, I want to click somewhere on the surface and I want the image to turn into that direction, so there are infinite number of rotations the object could make. Can somebody please give me a explanation on how to do this? 回答1: Image changing dimensions Surfaces in pygame can't