pygame

How to change background color of an OpenGL surface?

≯℡__Kan透↙ 提交于 2019-12-25 03:42:35
问题 Having srf = pygame.display.set_mode(viewport, OPENGL | DOUBLEBUF) and performing srf.fill([255,255,255]) results in the following error message: pygame.error: Cannot call on OPENGL Surfaces How to solve this issue? How can I change the background color? 回答1: You have to use the glClearColor function to set the color you want to clear your screen to, and then use glClear to actually clear the screen with the color specified. E.g. call glClearColor(0.7, 0, 0, 1) to set the color to red and

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

Bouncing an image in a polygonal way with pygame

我与影子孤独终老i 提交于 2019-12-25 02:58:52
问题 Hey guys am new to pygame .I have to make a ball image ball.jpg to bounce in polygonal way.I have also an another ball image which is running in a square way.What i need is to add an another ball image and bounce it in a polygonal way. My code is import pygame from itertools import cycle pygame.init() screen = pygame.display.set_mode((300, 300)) s_r = screen.get_rect() ball = pygame.image.load('ball.jpg') player = pygame.Rect((100, 100, 50, 50)) timer = pygame.time.Clock() speed = 5 up, down,

PyGame Collision detection for pong and keeping the paddles on screen

我怕爱的太早我们不能终老 提交于 2019-12-25 02:57:07
问题 So my problem here is that I don't want to use classes because I don't fully understand them yet nor do I want to use sprites. I have uploaded two images to the program I am able to move the paddles and get the ball to move and bounce off the top and bottom. However I cannot get the ball to bounce off the paddles. Also I cannot keep the paddles from going down off the screen or above off the screen. Any help would be appreciated thank you. import sys import pygame pygame.init() size = width,

Pygame 'LEFT' is not defined

泄露秘密 提交于 2019-12-25 02:53:10
问题 I'm working on a game. I have pygame imported. I am using Python 3.3 and Pygame 3.3. The same error message all the time "LEFT" is not defined. I did exact copies of what were on the internet as I already did a search for the problem. Here is my code. I have tried a few different ways and neither seem to work. method 1: import pygame event = pygame.event.poll() if event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT: ....command method 2: (basically going all in) from pygame import *

Pygame plays mp3 too fast (regardless of what frequency i define)

谁都会走 提交于 2019-12-25 02:32:53
问题 I´m playing an mp3 file I get after a request to google translate. When I play it through pygame it plays at twice the speed, regardless of what frequency I set in pygame.mixer.init() Here's the code: import tweepy, urllib, os, pygame, pycurl, difflib, time pygame.init() pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096) consumer_key = 'xxxxxxxxx' consumer_secret = 'xxxxxxxx' access_token = 'xxxxxx' access_token_secret = 'xxxxxx' auth = tweepy.OAuthHandler(consumer_key,

self.rect not found?

笑着哭i 提交于 2019-12-25 02:19:04
问题 I have a program that is simply made to move an image around. I try to state the self.rect as part of a load_png() call, but it simply does not like it. THe reason I think this will work is from http://www.pygame.org/docs/tut/tom/games6.html, saying that this should work: def __init__(self, side): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_png('bat.png') screen = pygame.display.get_surface() self.area = screen.get_rect() self.side = side self.speed = 10 self.state =

Livewires + Pygame Error

风流意气都作罢 提交于 2019-12-25 02:11:09
问题 So I am running Windows 8 with python 3.3 installed. I have livewires and pygame installed. But when I run the code: from livewires import games games.init(screen_width = 640, screen_height = 480, fps = 50) games.screen.mainloop() I get an error saying... ImportError: No module name 'pygame.image'. Does anyone know how to fix this? 回答1: Did you install pygame in the file directory of the python interpreter? But anyway pygame is not available for python 3.3 at the moment. If you want to use

Error while opening a python file converted into executable using cx_Freeze

亡梦爱人 提交于 2019-12-25 01:58:49
问题 I used cx_Freeze to convert a simple python program made using pygame and tkinter into an executable. However, when I try to open the .exe file. This is the setup.py file which I used to convert the game into executable import cx_Freeze import os.path PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__)) os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl','tcl8.6') os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6') executables = [cx_Freeze

Create an alternative form of questionnaire

本小妞迷上赌 提交于 2019-12-25 00:56:12
问题 I'm very new to programming in python so I'd appreciate any tips or hints as to where I can look: So what I basically planned on creating is a new form of questionnaire, where the respondent can express approval or disapproval to a question by dragging it from the center of the window into any part of a colored ring that surrounds the question, using the mouse. The ring is supposed to have two color gradients from green to red, and I want to be able to make my program (pygame?) track the