0

I'm brand new to Python, so this is probably a simple problem. I want the code to display "rotation: " followed by the value of the variable player_rotation. It does this, but the value displayed does not by 1 every iteration (as I would expect it to).

import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((480, 480))
myfont = pygame.font.SysFont("monospace", 15)
player_rotation = 0
rotation_label = myfont.render("rotation: " + str(player_rotation), 1, (255,255,0))

while 1:

    screen.blit(rotation_label, (100,100))
    player_rotation += 1
    pygame.display.flip()

for event in pygame.event.get():
    if event.type==pygame.QUIT:
        pygame.quit()
        exit(0)

3 Answers 3

1

You set the label only once and this occurs before the loop. Try moving rotation_label into your loop.

while 1:
    rotation_label = myfont.render("rotation: " + str(player_rotation), 1, (255,255,0))
    screen.blit(rotation_label, (100,100))
    player_rotation += 1
    pygame.display.flip()

Also, your code in for loop is never executed because it appears after your while 1

Sign up to request clarification or add additional context in comments.

Comments

0

You forgot to put tab spaces in your while(1) loop. That is:

while 1:
    screen.blit(rotation_label, (100,100))
    player_rotation += 1
    pygame.display.flip()

1 Comment

Damn. Formatting got messed up. The code is indented properly in PyCharm, but it still displays and unchanging "rotation: 0" when I run it. Edited my post to reflect the true formatting
0

You just update the variale player_rotation, but you never render you label it anew.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.