python - Printing Score - Pygame -
does know how can score displayed on screen of game?
so far have code:
for bullet in bullet_list: block_hit_list = pygame.sprite.spritecollide(bullet, block_list, true) block in block_hit_list: explosion.play() bullet_list.remove(bullet) all_sprites_list.remove(bullet) score += 10 font = pygame.font.font(none, 36) text = font.render(score, 1, (white)) textpos = text.get_rect(centerx=background.get_width()/2) background.blit(text, textpos) if bullet.rect.y < -10: bullet_list.remove(bullet) all_sprites_list.remove(bullet) however, recieve error once launch game , shoot bullet:
"text = font.render(score, 1, (white))
typeerror: text must unicode or bytes"
does know how can solve issue?
thank you
ok first of asked how correctly draw site how previous answer did it, wrong in way blit screen.
you have score blit screen every time through loop, causes have effect you're experiencing. should after loop. example:
for bullet in bullet_list: block_hit_list = pygame.sprite.spritecollide(bullet, block_list, true) block in block_hit_list: explosion.play() bullet_list.remove(bullet) all_sprites_list.remove(bullet) score += 10 #removed line!!!! ~ font = pygame.font.font(none, 36) #removed line to!!!! ~ text = font.render(score, 1, (white)) #remove line also!!! ~ textpos = text.get_rect(centerx=background.get_width()/2) #finally remove line!!!! ~ background.blit(text, textpos) if bullet.rect.y < -10: bullet_list.remove(bullet) all_sprites_list.remove(bullet) #add in removed lines after loop. font = pygame.font.font(none, 36) text = font.render(score, 1, (white)) textpos = text.get_rect(centerx=background.get_width()/2) background.blit(text, textpos) this should work. please tell me if need further help.
Comments
Post a Comment