Python pygame.translation.rotation有问题

Python pygame.translation.rotation有问题,python,pygame,Python,Pygame,所以我在测试一场比赛的轮换。 这是代码 import pygame from pygame.locals import * pygame.init() mainClock = pygame.time.Clock() degree = 0 WHITE = 250,250,250 rect2 = pygame.rect = (100,100,50,50) WINDOWWIDTH = 1200 WINDOWHEIGHT = 750 thing = pygame.image.load('thing.

所以我在测试一场比赛的轮换。 这是代码

import pygame
from pygame.locals import *

pygame.init()
mainClock = pygame.time.Clock()
degree = 0
WHITE = 250,250,250
rect2 = pygame.rect = (100,100,50,50)
WINDOWWIDTH = 1200
WINDOWHEIGHT = 750

thing = pygame.image.load('thing.bmp')
screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('Teh test')

while True:
    rect2 = pygame.rect = (100,100,50,50)
    degree += 2

    if degree >= 50:
        degree = 0

    screen.fill((40, 40, 40))
    thing = pygame.transform.rotate(thing,degree)
    pygame.draw.rect(screen,WHITE,rect2)
    screen.blit(thing,(100,100))
    pygame.display.update()
    mainClock.tick(60)
所以问题是,当我运行它时,矩形变大,图像从屏幕上旋转。我做错了什么? (答案越多越好)谢谢


(在该版本中使用python 3.3和pygame。)

您不应该覆盖
内容。这样你就可以累积学位

首先,你旋转
物体
2度,比你旋转
物体
4度+2度,比你旋转
物体
6度+4度,比你旋转
物体
6度+4度,比你旋转
物体
2度+12度,以此类推

degee>=50
时,您得到
degee=0
,但您仍然旋转了
对象(50+48+46+…+2)

使用
thing2

import pygame
from pygame.locals import *

#----------------------------------------------------------------------
# constants 
#----------------------------------------------------------------------

WHITE = 250,250,250
WINDOWWIDTH = 1200
WINDOWHEIGHT = 750

#----------------------------------------------------------------------
# game
#----------------------------------------------------------------------

pygame.init()
mainClock = pygame.time.Clock()

screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('Teh test')

#thing = pygame.image.load('thing.bmp')
thing = pygame.image.load('player.png')

rect2 = pygame.rect = (100,100,50,50)

degree = 0

#----------------------------------------------------------------------
# mainloop
#----------------------------------------------------------------------

running = True
while running:

    # events

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                running = False

    # calculations

    degree += 2

    if degree >= 50:
        degree = 0

    thing2 = pygame.transform.rotate(thing, degree)

    # draws

    screen.fill((40, 40, 40))
    pygame.draw.rect(screen,WHITE,rect2)
    screen.blit(thing2,(100,100))

    pygame.display.update()

    # clock

    mainClock.tick(30)

#----------------------------------------------------------------------
# exit
#----------------------------------------------------------------------

pygame.quit()
顺便说一句:永远不要覆盖oryginal图像,因为即使旋转360度,图像也不会像oryginal那样漂亮


代码“player.PNG”中使用的我的PNG图像

游戏中的PNG(Python 2.7,Linux Mint 16)


我很好奇为什么“答案越多越好”。一个好的答案不就足够了吗?如果不是这样的话,问题就太广泛了。(我不认为这里是这样。)我问的最后一个问题很复杂,很多人都回答错了。考虑到这些答案没有一个被你认为是正确的,显然更多的答案并不意味着一个好答案。它增加了找到一个好答案的机会。所以我尝试了一下。。。旋转的物体周围有一个正方形。我怎样才能摆脱它?(它也会改变大小。)我使用PNG图像-可能是BMP文件有问题。我和我的图片来回答。我添加PNG和截图来回答。谢谢。当我遇到问题时,我会问一系列的问题。所以只要不时检查我的问题就行了。