pygame

Receiving ValueError: invalid recstyle object

。_饼干妹妹 提交于 2021-02-17 02:06:18
问题 I am following the instructions of a pygame project on youtube, this is the video, I am on the project called "Snake", and in the description of the video, you can find what time it starts and the actual code. I am about 10 minutes into the video. I will show you the code that I have written so far: # Snake project on python import math import random import pygame import tkinter as tk from tkinter import messagebox class cube(object): rows = 0 w = 0 def __init__(self, start,dirnx=1, dirny=0,

How to install pygame automatically when virtual environment is created?

↘锁芯ラ 提交于 2021-02-17 02:06:09
问题 I am creating a virtual environment testenv to run some python project. This is my environment.yml file: name: testenv channels: - !!python/unicode 'defaults' dependencies: - python=3.5 - pip==9.0.1 - numpy==1.12.0 - jupyter==1.0 - matplotlib==2.0.0 - scikit-learn==0.18.1 - scipy==0.19.0 - pandas==0.19.2 - pip: - tensorflow==1.1.0 - keras==2.0.4 - plotly==2.7.0 I want to add pygame to this environenment. However, if I add pygame==1.9.4 to dependencies or pip , then the creation of a virtual

Dragging object along x-axis in pygame

99封情书 提交于 2021-02-17 02:06:04
问题 I want to be able to drag the blue object along the x-axis (black line) using mouse so that it does not move in y-direction. When I try to drag it, nothing happens. Where is the problem? import pygame def initialize(): pygame.init() global height, width height = 600 width = 900 screen = pygame.display.set_mode((width, height)) screen.fill((255, 255, 255)) pygame.draw.line(screen, (0, 0 ,0), (0, height / 2), (width, height / 2), 3) return screen def object(): dragging = False object_1 = pygame

Receiving ValueError: invalid recstyle object

橙三吉。 提交于 2021-02-17 02:05:44
问题 I am following the instructions of a pygame project on youtube, this is the video, I am on the project called "Snake", and in the description of the video, you can find what time it starts and the actual code. I am about 10 minutes into the video. I will show you the code that I have written so far: # Snake project on python import math import random import pygame import tkinter as tk from tkinter import messagebox class cube(object): rows = 0 w = 0 def __init__(self, start,dirnx=1, dirny=0,

How do I get the Mouse Position on a Pygame Scaled Surface?

社会主义新天地 提交于 2021-02-17 01:50:39
问题 The game I'm making blits everything onto a pygame.surface which is then scaled to the size of the user's display, maintaining aspect ratio, before the surface is then blitted to the main screen. The problem I'm having now, is that when I query the mouse position (because I want to do a hover effect on certain sprites), it's way off where the sprite is but the x and y match the sprite's coords. Is this because I've scaled the surface? And if so, is there a built-in Pygame method for assigning

How do I get the Mouse Position on a Pygame Scaled Surface?

眉间皱痕 提交于 2021-02-17 01:50:05
问题 The game I'm making blits everything onto a pygame.surface which is then scaled to the size of the user's display, maintaining aspect ratio, before the surface is then blitted to the main screen. The problem I'm having now, is that when I query the mouse position (because I want to do a hover effect on certain sprites), it's way off where the sprite is but the x and y match the sprite's coords. Is this because I've scaled the surface? And if so, is there a built-in Pygame method for assigning

How do I get the Mouse Position on a Pygame Scaled Surface?

大兔子大兔子 提交于 2021-02-17 01:48:46
问题 The game I'm making blits everything onto a pygame.surface which is then scaled to the size of the user's display, maintaining aspect ratio, before the surface is then blitted to the main screen. The problem I'm having now, is that when I query the mouse position (because I want to do a hover effect on certain sprites), it's way off where the sprite is but the x and y match the sprite's coords. Is this because I've scaled the surface? And if so, is there a built-in Pygame method for assigning

Raspberry pi with pygame.mixer audio produces only static

爷,独闯天下 提交于 2021-02-16 21:14:05
问题 I'm quite new with raspberry pi and am very new but I am trying to play an audio file through a python file on a pi B. I played the audio from the command line using omxplayer and it worked fine but when i run the following code it plays only static. from pygame import mixer mixer.init() wow = mixer.Sound('Wow.mp3') wow.play() time.sleep(5) I tried using mixer.load('Wow.mp3') and other variations but still only get static. I tried putting things in the init like mixer.init(4800, -16, 1, 1024)

python pygame blit. Getting an image to display

纵然是瞬间 提交于 2021-02-16 21:14:05
问题 I'm trying to get my webcam to show video through pygame. Here is the code: # import the relevant libraries import time import pygame import pygame.camera from pygame.locals import * # this is where one sets how long the script # sleeps for, between frames.sleeptime__in_seconds = 0.05 # initialise the display window pygame.init() pygame.camera.init() screen = pygame.display.set_mode((640, 480), 0, 32) # set up a camera object cam = pygame.camera.Camera(0) # start the camera cam.start() while

Pygame music pause/unpause toggle

蓝咒 提交于 2021-02-16 20:56:17
问题 Okay here's my code: def toggleMusic(): if pygame.mixer.music.get_busy(): pygame.mixer.music.pause() else: pygame.mixer.music.unpause() ---event handling--- if pressed 'm' it should toggle whether the music is paused and not paused toggleMusic() It can pause the music but not unpause, any explanation? 回答1: Had the same problem. For others' reference, my solution was to use a simple class. class Pause(object): def __init__(self): self.paused = pygame.mixer.music.get_busy() def toggle(self): if