【发布时间】:2015-05-18 10:45:25
【问题描述】:
我想用 pygame 绘制一个生命条,使用一个剪切区域(例如,当一半的生命值消失时,将区域限制为一半。) 但即使剪切区域是正确的,我总是能得到完整的图像。
那是我的救生圈课:
class Lifebar():
def __init__(self,x,y,images,owner):
self.x=x
self.y=y
self.images=images
self.owner=owner
self.owner.world.game.addGUI(self)
self.inter=False
def getValues(self):
value1 = 1.0 * self.owner.hitpoints
value2 = 1.0 * self.owner.maxhitpoints
return [value1,value2]
def render(self,surface):
rendervalues = self.getValues()
maxwidth = self.images[0].get_width()
ratio = rendervalues[0] / rendervalues[1]
actwidth = int(round(maxwidth * ratio))
surface.blit(self.images[0],(self.x,self.y))
surface.set_clip(self.x, 0, (self.x+actwidth), 1080)
surface.blit(self.images[1],(self.x,self.y))
self.owner.world.game.setclipDefault()
surface.blit(self.images[2],(self.x,self.y))
我检查了生命值未满,并且剪切区域在 x 方向上受到限制。 (get_clip()) 我不知道我是否误解了 set_clip() 的工作原理,因为我之前只将它用于整个屏幕(部分超出屏幕的对象)
【问题讨论】:
标签: pygame