pygame-surface

Is there any other way to load a resource like an image, sound, or font into Pygame? [closed]

孤街醉人 提交于 2021-01-29 22:16:14
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 months ago . Improve this question I am working on a game in pygame and I published some of my previous games on itch.io. When I am loading image I used to do it like this: player = pygame.image.load(r"C:\Users\user\folder\folder1\player.png") But when I publish the game, other people can't run the game. How

Lag when win.blit() background pygame

旧巷老猫 提交于 2021-01-29 22:13:20
问题 I'm having trouble with the framerate in my game. I've set it to 60 but it only goes to ~25fps. This was not an issue before displaying the background (was fine with only win.fill(WHITE) ). Here is enough of the code to reproduce: import os, pygame os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (50, 50) pygame.init() bg = pygame.image.load('images/bg.jpg') FPS = pygame.time.Clock() fps = 60 WHITE = (255, 255, 255) BLUE = (0, 0, 255) winW = 1227 winH = 700 win = pygame.display.set_mode((winW,

Pygame sprite not moving while jumping

空扰寡人 提交于 2021-01-28 11:26:46
问题 I'm confused why my sprite is not moving while jumping. I've checked several times and changed my code over and over with no luck. My code is below and contains 3 pages, first contain the main loop, second contain the player class and third contain some game functions. Main import pygame from player import Player import game_functions as gf import sys import time def run_game(): # Intialise the game and start the screen pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display

Ship moves up and left faster than down and right when rotating in pygame

被刻印的时光 ゝ 提交于 2021-01-28 09:55:35
问题 I am working on a simple game. I created a pygame sprite which and tested it by making it move forward and rotating at a consistent speed. However, it seams to be moving left and up (where sin and cos are negative) quicker than right and down (where sin and cos are positive). I tested it without moving and just rotating and it works. Here is the code: import pygame import sys from math import cos, sin, pi from time import sleep SCREEN_WIDTH = 800 SCREEN_HEIGHT = 800 FPS = 60 pygame.init()

Ship moves up and left faster than down and right when rotating in pygame

安稳与你 提交于 2021-01-28 09:55:32
问题 I am working on a simple game. I created a pygame sprite which and tested it by making it move forward and rotating at a consistent speed. However, it seams to be moving left and up (where sin and cos are negative) quicker than right and down (where sin and cos are positive). I tested it without moving and just rotating and it works. Here is the code: import pygame import sys from math import cos, sin, pi from time import sleep SCREEN_WIDTH = 800 SCREEN_HEIGHT = 800 FPS = 60 pygame.init()

Pygame surface with alpha not blitting transparency

℡╲_俬逩灬. 提交于 2021-01-28 03:30:19
问题 I'm trying to make a user interface thing transparent in my game when the mouse isn't hovering over it. But for some reason, when I set the alpha value of the image for it to become transparent, nothing happens. Here is some runnable code for it that replicates the problem: import pygame WHITE = (255, 255, 255) class UI: def __init__(self): self.img = pygame.image.load("ink_bar_solid.png") self.img.set_alpha(0) self.ink_bar_rect = self.img.get_bounding_rect() self.x, self.y = 0, 10 resolution

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

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__

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 #