您可以在中心位置对图像进行校正/移位吗?

问题描述 投票:0回答:1

我图像的矩形位于图像的右侧,我想将矩形向左移动几个像素或向右移动图像。另外,有没有办法使矩形向下移动或使顶部变小而矩形的底部保持不变?

PLAYER_RECT_HIT = py.Rect(0, 0, 33, 33)
class Player(py.sprite.Sprite):
    def __init__(self, game, x, y):
        self._layer = PLAYER_LAYER
        self.groups = game.all_sprites
        py.sprite.Sprite.__init__(self, self.groups)
        self.game = game
        self.running = False
        self.jumping = False
        self.wallSlide = False
        self.current_frame = 0
        self.last_update = 0
        self.load_images()
        self.image = self.idle_frames[0]
        self.rect = self.image.get_rect()
        self.rect.center = (x, y)
        self.hit_rect = PLAYER_RECT_HIT
        self.hit_rect.center = self.rect.center
        self.pos = vec(x, y)
        self.vel = vec(0, 0)
        self.acc = vec(0, 0)
python pygame collision rect
1个回答
0
投票

如果要使矩形的顶部变小而底部保持在同一位置,则可以这样做:

newRect = pygame.Rect(
    oldRect.top - 10, 
    oldRect.left, 
    oldRect.width - 10, 
    oldRect.height
)

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.