pygame

Enemy character is being overdrawn by game's background

那年仲夏 提交于 2019-12-22 18:19:52
问题 I am working on a game which spawns enemies. Though once these enemies are spawned, they instantly disappear again because the background is drawn on top of them. Is there a way to have a layer system in Pygame? Code to recreate the problem: import pygame import threading from random import randint from time import sleep pygame.init() window = pygame.display.set_mode((900, 900)) bg=pygame.image.load("Background.png").convert() def Gameplay(): while True: window.blit(bg, [0,0]) pygame.display

Pygame mixer only plays one sound at a time

拟墨画扇 提交于 2019-12-22 14:56:10
问题 Here is my code: pygame.mixer.init(frequency=22050,size=-16,channels=4) sound1 = pygame.mixer.Sound('sound1.wav') sound2 = pygame.mixer.Sound('sound2.wav') chan1 = pygame.mixer.find_channel() chan2 = pygame.mixer.find_channel() chan1.queue(sound1) chan2.queue(sound2) time.sleep(10) I would think it would play sound1 and sound2 simultaneously ( queue is non-blocking and the code immediately hits the sleep). Instead, it plays sound1 and then plays sound2 when sound1 is finished. I've confirmed

Change the position of the origin in PyGame coordinate system

拟墨画扇 提交于 2019-12-22 13:59:12
问题 I am doing some operations with vectors and physics in PyGame and the default coordinate system is inconvenient for me. Normally the (0, 0) point is at the top-left corner, but I would rather that the origin were at the bottom-left corner. I would rather change the coordinate system than converting every single thing I have to draw. Is it possible to change the coordinate system in PyGame to make it work like this? 回答1: Unfortunately, pygame does not provide any such functionality. The

How to rotate 2 objects independently in pygame and pyopengl

不想你离开。 提交于 2019-12-22 13:11:30
问题 I'm trying to rotate 2 objects independently but when I run the code both objects rotate in the same direction enter code here here i save the matrix and rotate a square under the cube def rotate_square(): glColor3f(1,1,1) glMatrixMode(GL_MODELVIEW) glPushMatrix() glRotatef(45,0,1,0) glBegin(GL_LINES) glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v3); glVertex3fv(v4); glVertex3fv(v2); glVertex3fv(v4); glEnd() glPopMatrix() main function def main(): pygame

Pygame scaling a sprite

烂漫一生 提交于 2019-12-22 10:49:07
问题 How would one scale a sprite's image to be bigger or smaller? I can change the rect and all, but not the image. Code:(though i'm not sure why you would need it for this) class test(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load("testImage.png").convert() self.image.set_colorkey((255,255,255)) self.rect = self.image.get_rect() 回答1: Have you tried pygame.transform.scale() Official documentation notes that you should use this syntax:

Is there an effiecient way of making a function to drag and drop multiple png's?

廉价感情. 提交于 2019-12-22 09:26:01
问题 I'm making a chess game, but I'm completely stuck on the drag and drop element, there's a few guides out there but they're all either dragging shapes, or only dragging one image. I've tried several variants of code, but all were 50+ lines just to move one .png and most were incredibly inefficient pygame.init() pygame.display.set_caption("Python Chess") clock = pygame.time.Clock() red = (213,43,67) chew = pygame.image.load("chew.png") gameDisplay.fill(red) gameDisplay.blit(chew, (400, 400))

Rotation in pygame

不打扰是莪最后的温柔 提交于 2019-12-22 08:05:33
问题 I've been looking for solutions on how to make my image rotate around a single point but from what I've found nothing has really worked. What I know I can rotate using pygame.transform.rotate(surface, angle) I need to constantly reset the center so the image does not rotate on its rotated self. Need to update image to eliminate distortion At first the image looks like this Then when I rotate it a couple times it looks like this Here's my code import pygame class pyGameSetup: def __init__(self

using threading in pygame

拥有回忆 提交于 2019-12-22 07:24:06
问题 I have a raspberry pi and on one of the gpio pins I am sending pulse, thus I have python code to detect interrupt on that pin and their are at most 2 interrupts every seconds. Now I want to pass this value(total no. of interrupts) to pygame application. Currently python code for detecting interrupts writes total no. interrupts to file as interrupt is detected and then pygame application reads that number from the file. Thus my question how can I integrate interrupt detecting code in pygame

transforming images in pygame

大憨熊 提交于 2019-12-22 06:59:38
问题 I'm trying to resize an image in pygame. I want my background image to fill the entire screen. I'd like to setup the entire screen based on the new (stretched) dimensions of the background. The following isn't working and I'm trying to figure out why. Suggestions? background = pygame.image.load("data/stars.bmp") pygame.transform.scale(background, (1200,800)) #or some size x,y here. bgRect = background.get_rect() size = width, height = bgRect.width, bgRect.height screen = pygame.display.set

Why does the pygame window not close properly?

霸气de小男生 提交于 2019-12-22 06:00:22
问题 When I go to close the program window, the program freezes, then I am forced to force quit the program. Why doesn't the program close when the X / Close button is clicked on. I am also using python 2.7 if that matters. import pygame import os, sys from itertools import * from oryxsprites import * from oryxbackground import * running = True while running: backgroundmain() pygame.display.set_caption('OryxGame') #pygame.display.set_icon(biggrasstile) for event in pygame.event.get(): if event