图像的中心是佳能的旋转点。您可以将图像缩放到所需的任何大小。例如100x100:
self.shootsright = pygame.image.load("canss.png")self.shootsright = pygame.transform.smoothscale(self.shootsright, (100, 100))
另请参阅如何将图像(播放器)旋转到鼠标方向?。
无论如何,在旋转图像并计算矩形后,您必须将大炮 变灰 。
class enemyshoot: def __init__(self,x,y,height,width,color): self.x = x self.y = y # [...] self.shootsright = pygame.image.load("canss.png") self.shootsright = pygame.transform.smoothscale(self.shootsright, (100, 100)) self.image = self.shootsright self.rect = self.image.get_rect(center = (self.x, self.y)) self.look_at_pos = (self.x, self.y) self.hitbox = (*self.rect.topleft, *self.rect.size) def draw(self): dx = self.look_at_pos[0] - self.x dy = self.look_at_pos[1] - self.y angle = (180/math.pi) * math.atan2(dx, dy) self.image = pygame.transform.rotate(self.shootsright, angle) self.rect = self.image.get_rect(center = (self.x, self.y)) window.blit(self.image, self.rect) self.hitbox = (*self.rect.topleft, *self.rect.size) def lookAt( self, coordinate ): self.look_at_pos = coordinate
最小示例:
[![](https://i.stack.imgur.com/5jD0C.png) repl.it/@Rabbid76/PyGame-RotateWithMouse](https://repl.it/@Rabbid76/PyGame-RotateWithMouse#main.py)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)