pygame

Use Pygame mouse while hidden

五迷三道 提交于 2020-01-07 02:29:08
问题 Is there a way to use the mouse while, pygame.mouse.set_visible(False) is activated. Currently mouse only returns the bottom-right coordinate when tried to be used. Being able to get correct coordinates while mouse is hidden is required. Could not find an answer at their documentation. 回答1: I solved the problem by using an invisible cursor. pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0)) 来源: https://stackoverflow.com/questions/40627934/use-pygame-mouse-while-hidden

Choosing a random sound Pygame

我们两清 提交于 2020-01-06 12:56:55
问题 I was wondering how to go about picking a random sound and playing it on an event in an OOP way. My original plan was have a list in my resource loader class, and have it iterate through that. My only issue is my code constantly breaks everything when I try to implement this. How would you guys go about this? 回答1: class SoundManager: sounds = [] # list of sound objects @staticmethod def playRandom(): random.choice(SoundManager.sounds).play() 来源: https://stackoverflow.com/questions/28865782

Pygame Binding Menu items to functions (by clicking)

浪子不回头ぞ 提交于 2020-01-06 12:50:41
问题 Modifying the Squirrel Eat Squirrel Pygame for a class project. Trying to add in a menu, with basic Start, Quit and Settings buttons. I have the buttons there, and they will light up as the mouse scrolls over them. However, I can't figure out how to call their respective functions when I click on them. I am trying to call them by this: def runMenu(self): mainloop = True while mainloop: self.__clock.tick(50) for event in pygame.event.get(): if event.type == pygame.QUIT: mainloop == False if

Pygame Multithreading

[亡魂溺海] 提交于 2020-01-06 10:15:33
问题 I have a multiplayer game that runs on pygame. I am running the game/client/server in separate threads and have a simple echo server. Each time a player broadcasts a message, every other player will get it. The problem I am experiencing is pygame has a while(true) loop that redraws the screen every 10 milliseconds. This loop causes the game world to not get updated since it cannot do anything outside the loop. I tried using a queue so that in the while loop, it can dequeue and process the

pyagme screen not working with multithreading

心不动则不痛 提交于 2020-01-06 09:04:52
问题 I am using python 2.7.14 and am currently trying to draw to 2 sides of a pygame screen simultaneously using the multiproccesing module(2 threads are calling functions from a single pygame screen) but everytime I call a function from screen(like screen.get_width() for example) the following error is raised: Process Process-1: Traceback (most recent call last): File "C:\Python27\lib\multiprocessing\process.py", line 267, in _bootstrap self.run() File "C:\Python27\lib\multiprocessing\process.py"

pyagme screen not working with multithreading

岁酱吖の 提交于 2020-01-06 09:04:20
问题 I am using python 2.7.14 and am currently trying to draw to 2 sides of a pygame screen simultaneously using the multiproccesing module(2 threads are calling functions from a single pygame screen) but everytime I call a function from screen(like screen.get_width() for example) the following error is raised: Process Process-1: Traceback (most recent call last): File "C:\Python27\lib\multiprocessing\process.py", line 267, in _bootstrap self.run() File "C:\Python27\lib\multiprocessing\process.py"

pyagme screen not working with multithreading

╄→гoц情女王★ 提交于 2020-01-06 09:04:18
问题 I am using python 2.7.14 and am currently trying to draw to 2 sides of a pygame screen simultaneously using the multiproccesing module(2 threads are calling functions from a single pygame screen) but everytime I call a function from screen(like screen.get_width() for example) the following error is raised: Process Process-1: Traceback (most recent call last): File "C:\Python27\lib\multiprocessing\process.py", line 267, in _bootstrap self.run() File "C:\Python27\lib\multiprocessing\process.py"

How do you convert 3d array in pygame to an vaid input in opencv python?

佐手、 提交于 2020-01-06 07:21:24
问题 I am trying to feed my screen input from game file to image processor file:- PyGame Output: image_data = pygame.surfarray.array3d(pygame.display.get_surface()) OpenCV input: imgTesting = cv2.imread(image_data) And the error I am getting is: imgTesting = cv2.imread(image_data) TypeError: bad argument type for built-in operation So how do I convert this 3d input to opencv friendly data so that I can do image processing? 回答1: imread() is used to read from file, not from memory. But you don't

Pygame time control

不打扰是莪最后的温柔 提交于 2020-01-06 02:50:08
问题 I've been thinking in pygame how can i control time. Namely, when an if-statement is True , i want it True just for some seconds, Which is the best pygame.time-object to use? Example if p.rect.left < self.rect.centerx < p.rect.right and self.rect.bottom >= 560: self.kill() p.image.fill(red) This is a ball bounce-collision and whenever this statement is True i want it to stay True just for an amount of time. How can I do that? :D 回答1: have you tried using the function pygame.time.get_ticks() ?

Pygame time control

霸气de小男生 提交于 2020-01-06 02:50:00
问题 I've been thinking in pygame how can i control time. Namely, when an if-statement is True , i want it True just for some seconds, Which is the best pygame.time-object to use? Example if p.rect.left < self.rect.centerx < p.rect.right and self.rect.bottom >= 560: self.kill() p.image.fill(red) This is a ball bounce-collision and whenever this statement is True i want it to stay True just for an amount of time. How can I do that? :D 回答1: have you tried using the function pygame.time.get_ticks() ?