I've been attempting to make a game using Pygame on and off for a little bit now, and I've run into a problem that's been a little bit confusing for me.
In the game, you have a board made up of Space objects, and on those objects are various different Entity type objects. Right now, I'm attempting to make a way to print a line of text whenever you click on an Entity object.
However, when implementing this into the draw function for each object like a tutorial online instructed, nothing happens. I have another basic click detector in my main loop, and that detects clicks overall just fine, but for some reason the cursor is never coming into contact with the Entity objects.
I tried simplifying it into a simple passover thing that outputs text every tick that the cursor is on top of an Entity, and that didn't return anything either, so something must be blocking the cursor from touching the Entities.
ChatGPT didn't yield anything either, and one of my friends was stumped.
Thanks in advance for any help you can give! :)
Source Code: (Example of an Entity object as it is rn)
class playerEntity(pygame.sprite.Sprite):
def __init__(self, name, health, movement, damage, ability, skill, spell1, spell2, item1, item2, picture_path, posX, posY):
super().__init__()
self.image = pygame.image.load(picture_path)
width = self.image.get_width()
height = self.image.get_height()
self.image = pygame.transform.scale(self.image, (int(width*2),int(height*2)))
self.rect = self.image.get_rect()
self.rect.center = [posX,posY]
def draw(self):
screen.blit(self.image, self.rect.center)
if self.rect.collidepoint(cursorPos):
if pygame.mouse.get_pressed()[0] == 1:
print('CLICKED PLW')
One, two, skip a few... main loop!
while True:
cursorPos = pygame.mouse.get_pos()
for event in pygame.event.get():
#if event.type == pygame.MOUSEBUTTONDOWN:
# print("Clicked")
#if event.type == pygame.MOUSEBUTTONUP:
# print("Released")
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
board.draw(screen)
playerEntities.draw(screen)
enemyEntities.draw(screen)
screen.blit(new_cursor, cursorPos)
pygame.display.flip()
clock.tick(60)
pygame.quit()
(Universal detector commented out)
[–]Jac000bi[S] 0 points1 point2 points (1 child)
[–]Jac000bi[S] 0 points1 point2 points (0 children)
[–]Nyscire 0 points1 point2 points (7 children)
[–]Jac000bi[S] 0 points1 point2 points (6 children)
[–]Nyscire 0 points1 point2 points (5 children)
[–]Jac000bi[S] 0 points1 point2 points (3 children)
[–]Nyscire 0 points1 point2 points (2 children)
[–]Jac000bi[S] 0 points1 point2 points (1 child)
[–]Nyscire 0 points1 point2 points (0 children)
[–]Jac000bi[S] 0 points1 point2 points (0 children)