pygame

Pygame surface with alpha not blitting transparency

℡╲_俬逩灬. 提交于 2021-01-28 03:30:19
问题 I'm trying to make a user interface thing transparent in my game when the mouse isn't hovering over it. But for some reason, when I set the alpha value of the image for it to become transparent, nothing happens. Here is some runnable code for it that replicates the problem: import pygame WHITE = (255, 255, 255) class UI: def __init__(self): self.img = pygame.image.load("ink_bar_solid.png") self.img.set_alpha(0) self.ink_bar_rect = self.img.get_bounding_rect() self.x, self.y = 0, 10 resolution

Is there a way to change the location and size of an imported .obj file in Pygame?

北慕城南 提交于 2021-01-28 03:25:54
问题 I created an .obj file using blender and loaded into Pygame using the OBJfileloader as sugested by skrx in: Error in OBJFileLoader Is there an easy way to change the location, height and width of the imported .obj file after importing it into Pygame? As an example, if you create a tree.obj file, to be able to place that same tree in different places with different sizes? Following the code below, maybe something like: object_obj = OBJ("Tree.obj", swapyz=False) object_obj.setX = 0 object_obj

pygame collision detection causes my computer to hang

瘦欲@ 提交于 2021-01-28 02:53:24
问题 I am trying to make a game similar to agar.io. I have a blob which is controlled by the player. It can move around and eat food. There is a different class for food as well. 200 instances of the food class is created: def spawn_food(self): if len(self.foods) <= 200: self.foods.append(Food()) Everything upuntil now is working fine, however, my entire computer hangs if i try to run the collision detection between all the foods and the blob. This is the code: def ate(self): for food in self

Pygame: Image chasing the mouse cursor from certain length [duplicate]

浪子不回头ぞ 提交于 2021-01-28 02:07:41
问题 This question already has answers here : How to make smooth movement in pygame (2 answers) How to make enemy follow player in pygame? [duplicate] (2 answers) Enemy doesn't follow player (pygame) [duplicate] (2 answers) Closed 4 months ago . Initially the image starts moving in the direction (0,0). During each frame, the object looks at the current location of the cursor using pygame.mouse.get_pos() and updates it's direction to be direction = .9*direction + v where v is a vector of length 10

pygame not importing in Python 3.6.4

夙愿已清 提交于 2021-01-28 01:41:25
问题 As a caveat, I have searched and tried every solution on could find on this topic here, on YouTube and anywhere google brought me to. Running Windows 10 Home 64 bit and Python 3.6.4. Pygame is displaying as an available module when I call a list of all modules via print (help('modules') ). But when I import it I get: from pygame.base import * ModuleNotFoundError: No module named 'pygame.base' or help('pygame') problem in pygame - ModuleNotFoundError: No module named 'pygame.base' I have have

How to add afterimages in pygame?

﹥>﹥吖頭↗ 提交于 2021-01-28 01:31:31
问题 Since character movement is grid based, characters look a bit odd when going from square to square as they just appear from one square onto another. To make the movement feel more natural, I wanted to add "afterimages" so that there would be a simulation of smooth movement. Demonstrational image: Since my code has characters moving directly onto the next square, I don't know how to blit sprites in between. if IDO.get_key(pygame.K_RIGHT): if PhaseFocus == 0 or PhaseFocus == 2: Reticlex +=1 if

Pygame: Checking if button is pressed

百般思念 提交于 2021-01-28 00:10:51
问题 I'm working on the start menu for my game in python using pygame, I made a function that detects if the mouse pressed on the position of each button and if it does, it changes the value of a boolean asigned to said button. However the boolean values are not changing. Here is my code: import pygame import sys import sqlite3 as lite # questions option_1 = option_2 = option_3 = option_4 = '' # misc initial_pos = 220 event_i = False event_g = False event_t = False event_e = False ... # Button

how to change the image dimensions to get my convolution algorithm working

孤者浪人 提交于 2021-01-27 23:03:31
问题 Basically pygame.surfarray.pixels3d returns a (672,672,3) shaped array which gives the error: Resources exhausted but it works when I pass an array of (6,30,30) . Any help would be appreciated. import numpy import random from DeepRTS import PyDeepRTS from Algorithms.DQN2.DQN import DQN # Start the game g = PyDeepRTS('21x21-2v2.json') # Add players player1 = g.add_player() player2 = g.add_player() #player3 = g.add_player() #player4 = g.add_player() # Set FPS and UPS limits g.set_max_fps

Cannot load music in Pygame

家住魔仙堡 提交于 2021-01-27 20:09:06
问题 The code I am using is this: import pygame assert pygame.init()==(6,0) pygame.mixer.init() from pygame.locals import * from time import sleep import os pygame.mixer.music.load('timer_end.mp3') Unfortunately, I get this error: Traceback (most recent call last): File "C:\Python37\Lib\timer.py", line 60, in <module> pygame.mixer.music.load('timer_end.mp3') pygame.error: Couldn't open 'timer_end.mp3' I have also looked at this question and its answer. They are, unfortunately, not helpful because

TypeError: object of type 'int' has no len() - Python/Pygame

家住魔仙堡 提交于 2021-01-27 18:24:24
问题 I am creating a cookie clicker game, where there is a surface that displays how many cookies I have. Here is my code for drawing text. def draw_text(self, text, font_name, size, color, x, y, align="nw"): font = pg.font.Font(font_name, size) text_surface = font.render(text, True, color) text_rect = text_surface.get_rect() self.screen.blit(text_surface, text_rect) Then in the new function of my game loop (for when a new game starts), I created a variable: def new(self): self.cookie_count = 0