pygame

Blitting images onto a tile that is part of a grid in pygame

天涯浪子 提交于 2020-01-05 04:11:06
问题 # User-defined functions def main(): # initialize all pygame modules (some need initialization) pygame.init() # create a pygame display window pygame.display.set_mode((500, 400)) # set the title of the display window pygame.display.set_caption('Memory') # get the display surface w_surface = pygame.display.get_surface() # create a game object game = Game(w_surface) # start the main game loop by calling the play method on the game #object game.play() # quit pygame and clean up the pygame window

TypeError: 'pygame.Surface' object is not callable

跟風遠走 提交于 2020-01-05 03:44:14
问题 I have this issue when I would like to go the Game Over screen. Traceback (most recent call last): File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 215, in <module> game() File "C:\Users\MO\Desktop\Twerk\ballbounce_changed.py", line 191, in game text("Game Over",30,white,300) TypeError: 'pygame.Surface' object is not callable This the section of the code for the exist screen: while finish == True: screen.blit(menu,[0,0]) text("Game Over",30,white,300) text("Instructions",310,white

Getting the center of surfaces in pygame with python 3.4

半城伤御伤魂 提交于 2020-01-05 03:06:33
问题 I'm having troubles getting the center of surfaces with pygame. It defaults to the upper left corner of surfaces when trying to place them on other surfaces. To demonstrate what I mean I wrote a short program. import pygame WHITE = (255, 255, 255) pygame.init() #creating a test screen screen = pygame.display.set_mode((500, 500), pygame.RESIZABLE) #creating the canvas game_canvas = screen.copy() game_canvas.fill(WHITE) #drawing the canvas onto screen with coords 50, 50 (tho its using the upper

Scaling an Image/Rectangle in Pygame

大憨熊 提交于 2020-01-05 03:05:09
问题 Is it possible to "scale" a rectangle inside of pygame. Kinda like when you scale your windows on your desktop, I'm wondering how you could do so in pygame. Your cursor will control the size of the rectangle. I used skrx method and I tried to do it for 2 rectangles: if evnt.type == MOUSEBUTTONDOWN: if winVirus.collidepoint(evnt.pos): rectVSelect = True elif winCrime.collidepoint(evnt.pos): rectCSelect = True elif evnt.type == MOUSEBUTTONUP: rectVSelect = False rectCSelect = False if evnt.type

How to animate scale and rotate in pygame using rotozoom

。_饼干妹妹 提交于 2020-01-04 15:27:53
问题 Okay so Im just trying to get it working with rotations first before scaling then once I nail that the rotozoom should be easy. For the life of me I cant seem to get it working. Heres a simple class that I want the object to rotate over time as well a transform in the x direction. The transform is working fine but i just cant get it to rotate. class Puff(pygame.sprite.Sprite): def __init__(self, screen): pygame.sprite.Sprite.__init__(self) self.screen = screen try: self.imagePuff = pygame

How to animate scale and rotate in pygame using rotozoom

一个人想着一个人 提交于 2020-01-04 15:26:55
问题 Okay so Im just trying to get it working with rotations first before scaling then once I nail that the rotozoom should be easy. For the life of me I cant seem to get it working. Heres a simple class that I want the object to rotate over time as well a transform in the x direction. The transform is working fine but i just cant get it to rotate. class Puff(pygame.sprite.Sprite): def __init__(self, screen): pygame.sprite.Sprite.__init__(self) self.screen = screen try: self.imagePuff = pygame

Why is Surface.unlock failing to unlock the surface for blitting?

北战南征 提交于 2020-01-04 12:49:54
问题 I'm trying to apply a numpy array of alpha values to a surface. I'm able to do so, but the surface remains locked after this operation such that I cannot blit the surface to my display. Below is a simple test case, using the alpha array, g , pickled here. import pygame as pg pg.init() screen = pg.display.set_mode((600, 600)) s = pg.Surface((100, 100)).convert_alpha() s.fill((126, 126, 126)) # make it grey pxa = pg.surfarray.pixels_alpha(s) # reference the alpha values pxa[::] = g # g is the

Why is Surface.unlock failing to unlock the surface for blitting?

孤者浪人 提交于 2020-01-04 12:49:31
问题 I'm trying to apply a numpy array of alpha values to a surface. I'm able to do so, but the surface remains locked after this operation such that I cannot blit the surface to my display. Below is a simple test case, using the alpha array, g , pickled here. import pygame as pg pg.init() screen = pg.display.set_mode((600, 600)) s = pg.Surface((100, 100)).convert_alpha() s.fill((126, 126, 126)) # make it grey pxa = pg.surfarray.pixels_alpha(s) # reference the alpha values pxa[::] = g # g is the

pygame key.set_repeat not working

梦想的初衷 提交于 2020-01-04 09:05:16
问题 I am new to pygame and I am trying to make pong in order to learn it. I am trying to make smooth controls so that holding down an arrow will work, but it is not working right now. import sys, pygame pygame.init() size = (500, 350) screen = pygame.display.set_mode(size) x = 1 xwid = 75 yhei = 5 pygame.key.set_repeat(0, 500) while True: vector = 0 for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: vector = 4

How do I implement a picture instead of my red rectangle?

六月ゝ 毕业季﹏ 提交于 2020-01-04 08:06:08
问题 I cant seem to add a picture from a file instead of the red rectangle that is being displayed. This is only one class of my code. I have looked at other tutorials on how to do this but i haven't had any luck. When i tried adding the image.load command, I kept getting a black window without anything on it. I would like the image to be displayed instead of the red rectangle, but still with the same x and y values etc. def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) self.x_change =