python - How do I make a rectangle invisible? (Pygame) -
this question has answer here:
- draw transparent rectangle in pygame 2 answers
image showing rectangles used collisions.
i making arcade-style game involves moving on-screen sprite. since in-game walls part of background image have set rectangles in order test when sprite collides wall (to block moving through example). know if there way make rectangles invisible or not viewable player (but still using them collisions). have used pygame.draw.rect() function create rectangles:
zone1rect = pygame.draw.rect(surf, (0,0,0), (200, 418, 52, 188), 1)
edit: possible create surface under main 1 add these to? , if still allow collision between sprite (which on different surface)? not asking aloha colours, please not assosciate question. question talks partly transparent rectangles, not want know.
you need pygame.rect()
use keep player position, check collision , blit player on screen.
player position , size
player_image = ... player_rect = pygame.rect(p_spritex, p_spritey, 30, 40)
check collision
player_rect.colliderect(enemy_rect)
draw player
surf.blit(player_image, player_rect)
and don't have use draw.rect
prect = pygame.draw.rect(surf, (0,0,0), (p_spritex, p_spritey, 30, 40), 1)
because useless
doc: pygame.rect
tutorial: program arcade games python , pygame
Comments
Post a Comment