pygame是一组用于编写视频游戏的Python模块。只有在使用pygame库时才使用此标记,如果您对python中的游戏编程有疑问,请不要使用此标记。
通过框架切换太快 我的角色非常快速地穿过框架,我不知道为什么。我尝试改变自我。Animation_speed,但除了在游戏启动时停滞以外,它没有做任何事情。有人可以...
Get_frect是get_rect的浮点,它的确有用。它来自pygame模块插件,称为“ pygame-ce'
我想编写一个MIDI文件,其中包括我从数字钢琴中收到的输入。我正在使用pygame.midi打开输入端口和Midiutil来编写MIDI文件。我无法包裹我的...
可以读取显示显示器的当前标志吗?因此,当一个人打电话给pygame.display.set_mode(分辨率,标志)时,我很想在之后阅读它们。 例如,我想哈...
aohoj, 在Pygame中,我试图设置图像的透明度。 我用这个: ship = pygame.image.load(os.path.join(dir,“ spacehip.png”)) ship.set_alpha(128) 问题: 该代码在MX
class Player: def __init__(self, x, y, width, height, speed, images_right, images_left, idle_image): self.x = x self.y = y self.width = width self.height = height self.speed = speed self.left = False self.right = False self.jump_status = False self.jump_time = 10 self.anim_num = 0 self.images_right = images_right self.images_left = images_left self.idle_image = idle_image self.hitbox = (self.x + 17, self.y + 11, 29, 52) self.health = 10 self.visible = True self.maxhealth = 10 self.score = 0 self.start = (x,y) def hit(self): if self.health > 0: self.health -= 1 else: self.visible = False print('hit') class ResettableSprite: def __init__(self, idle_image, x, y): self.idle_image = idle_image self.rect = self.image.get_rect() self.start_x = x self.start_y = y self.reset() def reset(self): self.rect.x = self.start_x self.rect.y = self.start_y self.health = Player.maxhealth player1 = Player(200, 317, 64, 64, 10, walkRight, walkLeft, char) player2 = Player(500, 285, 92, 85, 10, walkRight2, walkLeft2, dragon)
是否有用于捕获等距网格的算法? 这是我想到的: DEF ISO(参数0,参数1): a = round(pygame.mouse.get_pos()[1]/gright1 -pygame.mouse.get_pos()[0]/
如何在python/pygame中制作按钮? 我在pygame上制作游戏,在第一个屏幕上,我希望有一个按钮,您可以按(i)启动游戏,(ii)加载带有指令的新屏幕,(iii)退出程序。 我...
#load_image is used in most pygame programs for loading images def load_image(name, colorkey=None): fullname = os.path.join('data', name) try: image = pygame.image.load(fullname) except pygame.error, message: print 'Cannot load image:', fullname raise SystemExit, message image = image.convert() if colorkey is not None: if colorkey is -1: colorkey = image.get_at((0,0)) image.set_colorkey(colorkey, RLEACCEL) return image, image.get_rect() class Button(pygame.sprite.Sprite): """Class used to create a button, use setCords to set position of topleft corner. Method pressed() returns a boolean and should be called inside the input loop.""" def __init__(self): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_image('button.png', -1) def setCords(self,x,y): self.rect.topleft = x,y def pressed(self,mouse): if mouse[0] > self.rect.topleft[0]: if mouse[1] > self.rect.topleft[1]: if mouse[0] < self.rect.bottomright[0]: if mouse[1] < self.rect.bottomright[1]: return True else: return False else: return False else: return False else: return False def main(): button = Button() #Button class is created button.setCords(200,200) #Button is displayed at 200,200 while 1: for event in pygame.event.get(): if event.type == MOUSEBUTTONDOWN: mouse = pygame.mouse.get_pos() if button.pressed(mouse): #Button's pressed method is called print ('button hit') if __name__ == '__main__': main()
AttributeError: module 'pygame.math' has no attribute 'sin'
我目前正在尝试制作一个自上而下的射击游戏,但是当角色移动时(向上,向下,左和右)时,我遇到了一些麻烦,试图弄清楚如何移动地图。我希望地图始终填充屏幕,但是当角色移动时,地图将随着图像移动。我已经在网上寻找寻找一些解决方案,但是很难将其实施到我自己的程序中。