使用和制作精灵组

2024-10-04 07:38:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个精灵类角色,这个类有方法makeCharacter,add,remove

troll = Character()

#this makes 10 characters troll to appear at any position x,y given by the user.

makeCharacter(troll,10,[position])
remove(troll,3)
add(troll,10)

我想通过一种方法来确定字符图像,setImage

如果可能的话,精灵组中的所有巨魔都可以更改他们的图像,并且一个组中的单个精灵可以选择更改他们的图像。你知道吗

因此,如果troll.setImage("troll.png")被调用,那么巨魔的图像应该自动变为巨魔,如果另一个怪物被调用并应用了相同的对象,那么将为该精灵显示一个怪物的图片。你知道吗

到目前为止,对于makeCharacter,我有以下makeCharacter

def makeCharacters(self,Character, numberOfcharacters,[positionx, positiony]):
    for i in range(numberOfcharacters):
        self.trolls.add(troll, [positionx, positiony])
        self.window.blit(character.image,(positionx,positiony))

我不希望character类的character\uem>init\uem>构造函数初始化位置

这种方法行不通。你知道吗

有什么建议吗?你知道吗


Tags: 方法图像selfaddpositionremove精灵character