pygame

Why does the pygame window not close properly?

戏子无情 提交于 2019-12-22 06:00:03
问题 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

Is there any way to “clear” a surface?

自古美人都是妖i 提交于 2019-12-22 05:35:15
问题 Is there any way to clear a surface from anything that has been blitted to it? 回答1: When I dont care about performance, I use: mysurface.fill((0,0,0)) Which will draw the specified color (black in this case) across the entire surface. Is that what you meant by "clear"? Oh, and you need, of course, to "flip" the surface after doing this for it to be visible on the screen. 回答2: I don't know what API you're using, so here's a vague answer: In virtually all cases "clearing" a surface simply blits

Pygame simple loop runs very slowly on Mac

与世无争的帅哥 提交于 2019-12-22 04:43:15
问题 E: After testing the same on OS X and Linux, I can confirm that the following only happens on OS X. On Linux it literally runs at a thousand fps, as I happened to wonder. Any explanation? I would much prefer developing on Mac, thanks to TextMate. Here's a simple loop that does almost nothing, and still runs very slowly. Can anyone explain why? FPS averages at little over 30, it takes a little over 30ms for each pass over the loop. Window size does not seem to affect this at all, as even

NameError: name 'KEYDOWN' is not defined

▼魔方 西西 提交于 2019-12-21 22:21:17
问题 I am new to programming with PyGame and I've made this code: import sys, pygame pygame.init() size = width, height = 800, 600 speed = [2, 2] black = 1, 1, 1 screen = pygame.display.set_mode(size) ball = pygame.image.load("ball.bmp") ballrect = ball.get_rect() player1 = pygame.image.load("player1.png") player1rect = player1.get_rect() mod_x = mod_y = 0 while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == KEYDOWN: if event.key == K_W: movex = 2

Pygame not working with sockets

我与影子孤独终老i 提交于 2019-12-21 21:34:45
问题 I created one program with pygame, imageGrab and sockets but it doesn't work. It should take a printscreen of the server with ImageGrab, convert it to a string, and send it to the client. However, the client upon receiving the information and converting it to an image raises an error: image = pygame.image.frombuffer(img, (800,600), "RGB") ValueError: Buffer length does not equal format and resolution size code Server import sys, os, socket, pygame from PIL import ImageGrab from pygame.locals

How to enable autocomplete (IntelliSense) for python package modules?

对着背影说爱祢 提交于 2019-12-21 18:33:14
问题 This question is not about Pygame, I'm usin Pygame as an example. While experimenting with Pygame I've noticed that autocomplete is not working for some modules. For example, if I start typing pygame.mixer autocomplete shows MissingModule . While searching for a solution I've found a lot of similar questions for various text editors and modules that have parts written in C. I am using Visual Studio Code, python path is set correctly and my code runs fine. One strange workaround is modifying

pygame指针时钟实现

时光毁灭记忆、已成空白 提交于 2019-12-21 17:17:04
##python pygame实现指针时钟 有时间BUG,需要再修改下参数,另外退出的key有BUG,都留着供学习研究,保留不修改。 转载请注明出处 源码如下: ############### import pygame import os from pygame import * import math import datetime from datetime import datetime pygame.init() screen=display.set_mode((600,300)) font1=font.Font(None,20) pos_x=300 pos_y=150 while True: screen.fill((0,0,0)) if event in pygame.event.get(): if event.type==KEYDOWN: if event.key==pygame.K_a: print(1) draw.circle(screen,(255,255,255),(pos_x,pos_y),70,2) for n in range(1,13): ang=math.radians(n*30-90) x=math.cos(ang)*60+pos_x-4 y=math.sin(ang)*60+pos_y-5 font_img=font1.render(str(n

Press multiple keys at once to get my character to move diagonally

ⅰ亾dé卋堺 提交于 2019-12-21 16:24:31
问题 The problem I'm having is that I'm trying to make my character move diagonally on screen when a user presses either the K_UP key and K_RIGHT key or the K_UP key and K_DOWN key, etc. Here is my code for character movement (event handling): 1. #Event Handling 2. for event in pygame.event.get(): 3. if event.type == pygame.QUIT: 4. sys.exit() 5. elif (event.type == KEYDOWN): 6. if ((event.key == K_ESCAPE) 7. or (event.key == K_q)): 8. sys.exit() 9. if (event.key == K_UP): 10. self.char_y = self

recv() function too slow

為{幸葍}努か 提交于 2019-12-21 12:41:28
问题 Hi i'm quite a newbie to Python. I' writting a simple LAN game (not simple for me) using a pygame module. Here's the problem - I have two computers (one old intel Atom netbook, the other intel i5 NTB). I want to achieve at least 5 FPS (the netbook is slowering the NTB, but not so much, now i have around 1,5 FPS), but calling recv() function twice a main loop takes total around 0,5 seconds on each machine. The wifi signal is strong and the router is 300Mbit/s and it sends a short roughly 500

Process finished with exit code 139 after updating from python 2.7.6 64 bit to 2.7.10 32 bit

邮差的信 提交于 2019-12-21 06:16:27
问题 I have a script that opens images in a Tkinter frame with PIL/pillow. It was working fine yesterday when i was running python 2.7.6 64 bit , but in order to use Pygame later did i update to python 2.7.10 32 bit (pygame only runs on 32 bit). When running the same script today do i get Process finished with exit code 139, which i believe means Invalid memory access . If i run the script without running the function that includes pil.image will the script be executed normally. Anyone know how to