Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pygame类坐标(位置)和动画(pyganim)_Python_Class_Animation_Pygame_Sprite - Fatal编程技术网

Python Pygame类坐标(位置)和动画(pyganim)

Python Pygame类坐标(位置)和动画(pyganim),python,class,animation,pygame,sprite,Python,Class,Animation,Pygame,Sprite,我在编一个游戏。我遇到了一个问题,两到三天都找不到答案:/ 我的问题是,我试图应用动画,但我无法获得我的玩家类的坐标或位置(x,y) 我的播放器代码:(Sry用于坏空格,直接从我的.py文件粘贴:/) 编辑:如果您需要我添加代码的其他部分,请告诉我…在深入研究我的代码并尝试使用各种编码方法来解决我的问题后,我发现我已经创建了一个pygame player值,该值具有位置 class Entity(pygame.sprite.Sprite): def __init__(self): pyg

我在编一个游戏。我遇到了一个问题,两到三天都找不到答案:/

我的问题是,我试图应用动画,但我无法获得我的玩家类的坐标或位置(x,y)

我的播放器代码:(Sry用于坏空格,直接从我的.py文件粘贴:/)


编辑:如果您需要我添加代码的其他部分,请告诉我…

在深入研究我的代码并尝试使用各种编码方法来解决我的问题后,我发现我已经创建了一个pygame player值,该值具有位置

class Entity(pygame.sprite.Sprite):
def __init__(self):
    pygame.sprite.Sprite.__init__(self)

class Player(Entity):
def __init__(self, x, y):
    Entity.__init__(self)
    self.xvel = 0
    self.yvel = 0
    self.onGround = False
    self.image = Surface = pygame.image.load("PlayerModels\Sprites\PlayerStill.gif")
    self.rect = Rect(x, y, 32, 55)

def update(self, up, down, left, right, running, platforms):
    if up:
        # Pasokti tik ant zemes
        if self.onGround: self.yvel -= 10
    if down:
        pass
    if running:
        self.xvel = 12
    if left:
        self.xvel = -5
    if right:
        self.xvel = 5
        BegimoAnim.play()
    if not self.onGround:
        # gravitacija + acceleracija
        self.yvel += 0.3
        # Max kritimo greitis
        if self.yvel > 100: self.yvel = 100
    if not(left or right):
        self.xvel = 0
    # Prieaugis X direkcijoje
    self.rect.left += self.xvel
    # daryti X axis collision
    self.collide(self.xvel, 0, platforms)
    # Prieaugis Y direkcijoje
    self.rect.top += self.yvel
    # Ar ore?
    self.onGround = False;
    # daryti Y axis collision
    self.collide(0, self.yvel, platforms)



def collide(self, xvel, yvel, platforms):
    for p in platforms:
        if pygame.sprite.collide_rect(self, p):
            if isinstance(p, ExitBlock):
                pygame.event.post(pygame.event.Event(QUIT))
            if xvel > 0:
                self.rect.right = p.rect.left

            if xvel < 0:
                self.rect.left = p.rect.right

            if yvel > 0:
                self.rect.bottom = p.rect.top
                self.onGround = True
                self.yvel = 0
            if yvel < 0:
                self.rect.top = p.rect.bottom
    for y in range(32):
        for x in range(32):
            screen.blit(bg, (x * 32, y * 32))

    camera.update(player)


    player.update(up, down, left, right, running, platforms)
    for e in entities:
        screen.blit(e.image, camera.apply(e))
        BegimoAnim.blit(screen, (xPlayer, yPlayer)) #help in here, how to?? (BegimoAnim means RunningAnim)


    pygame.display.update()