pygame

What exactly does pygame.display.set_mode() do?

有些话、适合烂在心里 提交于 2021-01-27 04:45:37
问题 I've recently started to play around with the pygame python library and I just wanted to see if I was understanding something correctly: The following is some code that sets up the window. In the line that says: windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32) , does display refer to a module inside of pygame and is set_mode the name of a class in that module? Is this correct? from pygame.locals import * # set up pygame pygame.init() # set up the window WINDOWWIDTH

Make a line as a sprite with its own collision in Pygame

喜你入骨 提交于 2021-01-24 07:50:28
问题 I am making a game that connects a line between a 2 players. I want to make it so I can tell when an object (which is also a sprite) collides with the line. The way I thought of doing this is creating a line that acts a sprite. The line will be able to change length depending on where the players are. I'm a bit new to PyGame so I'm not too sure on what I have so far: class Line(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([400,400]

How to Display Sprites in Pygame?

雨燕双飞 提交于 2021-01-23 11:02:10
问题 This is just a quick question regarding sprites in PyGame, I have my image loaded as in the code below, and I'm just wondering how to display the sprite in PyGame like drawing a rectangle or circle. I don't want to have it behave in anyway. I think I use a blit command, but I'm not sure and I'm not finding much online. Here's my image code for loading it. Star = pygame.image.load('WhiteStar.png').convert_alpha() You could just provide an outline for loading a sprite. I simply want to display

Error while import pygame

三世轮回 提交于 2021-01-21 07:30:15
问题 I've installed pygame with Anaconda using the following command: conda install --channel https://conda.anaconda.org/kne pygame Then I tried to import pygame and I got the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/__init__.py", line 133, in <module> from pygame.base import * ImportError: dlopen(/Users/ejalaa/anaconda/lib/python2.7/site-packages/pygame/base.so, 2): Library not loaded:

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

不想你离开。 提交于 2021-01-20 13:41:13
问题 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 to save object using pygame.Surfaces to file using pickle

喜夏-厌秋 提交于 2021-01-20 13:40:09
问题 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__

Pygame error : video system not initialized [duplicate]

限于喜欢 提交于 2021-01-20 13:01:47
问题 This question already has an answer here : Why is my pygame window not opening after I close another window and producing an unexpected error? (1 answer) Closed last month . import sys,pygame pygame.init() size = width , height = 600,400 screen = pygame.display.set_mode(size) tux = pygame.image.load("tux.png") screen.blit(tux,(200,200)) screen.blit(tux,(0,0)) pygame.display.flip() while 1: ev = pygame.event.poll() if ev.type == pygame.QUIT: pygame.quit() The above code is showing this error -

Pygame error : video system not initialized [duplicate]

佐手、 提交于 2021-01-20 13:00:45
问题 This question already has an answer here : Why is my pygame window not opening after I close another window and producing an unexpected error? (1 answer) Closed last month . import sys,pygame pygame.init() size = width , height = 600,400 screen = pygame.display.set_mode(size) tux = pygame.image.load("tux.png") screen.blit(tux,(200,200)) screen.blit(tux,(0,0)) pygame.display.flip() while 1: ev = pygame.event.poll() if ev.type == pygame.QUIT: pygame.quit() The above code is showing this error -

Display SVG (from string) on Python Pygame

天大地大妈咪最大 提交于 2021-01-20 11:41:45
问题 I have an SVG graphic represented in a string svg_string='<svg height="100" width="500"><ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow" /><ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white" /></svg>' I want to display the graphics represented by svg_string , which is 2 ellipses, on a window initiated from Python. The pseudo code of which should be something like import pygame def display_svg_figure(screen, svg_string): # Code that draws the rendered SVG string on #

Pygame - Crashing when trying to shoot [closed]

我们两清 提交于 2021-01-20 08:52:19
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 21 days ago . Improve this question I am trying to learn Python and wanted to practice with Pygame. I am currently using Python 3.6.5 and running the code in Atom 1.27.2 and installed the atom-runner package. I have been following the KidsCanCode tutorial for Pygame on Youtube. I wanted to change