我目前正在研究一个项目,您可以在其中设置图像或颜色并拖动它们。因为您可以串连它的外观,所以我想给用户1命令。他们可以输入颜色或图像。根据女巫的输入,我必须对一些变量进行链接,以免颜色变白。有pygame命令可以测试输入的输入是图像还是颜色?
这是我使用此代码的部分
def set_appearance(self,appearance): #Enter 1 or 3 colours / images
if (): #If the input (appearance) is an image
self.type=1
if not len(appearance)==1:
size1=appearance[0].get_rect().size
size2=appearance[1].get_rect().size
size3=appearance[2].get_rect().size
if size1==size2 and size1==size3 and size2==size3:
self.w=size1[0]
self.h=size1[1]
self.allimg=None
self.inactive=appearance[0]
self.active=appearance[1]
self.drag=appearance[2]
else:
self.allimg=appearance[0]
self.w=self.allimg.get_width()
self.h=self.allimg.get_height()
if (): #If the input is a colour
self.type=0
if len(appearance)==3:
self.allcol=None
self.inactive=appearance[0]
self.active=appearance[1]
self.drag=appearance[2]
else:
self.allcol=appearance[0]
答案 0 :(得分:0)
你可以简单地:
if isinstance(Input, pygame.Surface):
# [...]