本文整理汇总了Python中pygame.Surface.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.__init__方法的具体用法?Python Surface.__init__怎么用?Python Surface.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.Surface
的用法示例。
在下文中一共展示了Surface.__init__方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import __init__ [as 别名]
def __init__(self):
scrsize = self.w, self.h = display.get_surface().get_size()
Surface.__init__(self, scrsize)
self.foo = 0
self.l0 = []
self.l1 = []
self.l2 = []
示例2: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import __init__ [as 别名]
def __init__(self, line, surf_w, justify):
# renders a line (list of tokens)
# accepts a line (list of tokens), width of line, and justification
# returns Surface object with the tokens justified upon it given the
# justify argument
self.line = line
self.links = defaultdict(list)
links = self.links
scale_token = _scale_token
# get the line width, line height, whitespace used in the line, and
# freespace remaining in the line
line_w = sum(token.get_width() for token in line)
line_h = max(token.get_height() for token in line)
total_whitespace = sum(token.get_width() for token in line
if token.iswhitespace)
freespace = surf_w - line_w # the freespace available in the surface
# initialize surface
Surface.__init__(self, (surf_w, line_h))
self.set_colorkey(BLACK)
# set x
if justify == 'right': x = freespace
elif justify == 'center': x = freespace / 2
else: x = 0
# if justified: modify whitespace widths
if justify == 'justified':
# the amount to stretch whitespace
stretch = 1.0 + (freespace / total_whitespace)
sub_w = 0
for i, token in enumerate(line):
if token.iswhitespace:
# replace token with a scaled token
token_w = token.get_width() * stretch
scale_w = int(token_w)
sub_w += token_w % scale_w
while sub_w > 1:
sub_w -= 1
scale_w += 1
line[i] = scale_token(token, (scale_w, token.get_height()))
for token in line:
w, h = token.get_size()
y = (line_h - h) # token y
self.blit(token, (x, y))
for link in token.links:
for rect in token.links[link]:
# move rect to token's position in line and append to links
links[link].append(rect.move(x, y))
x += w # update x with object width
示例3: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import __init__ [as 别名]
def __init__(self, position, size, passenger, resource_path):
Surface.__init__(self, size)
self.position = position
self.size = size
self.passenger = passenger
self.text_font = font.Font(None, 15)
self.passenger_surface = Surface(self.size).convert()
self.rect = Rect(self.position, self.size)
self.option_image = transform.scale(image.load(resource_path+"Images/option_icon.png"), (20, 20))
self.option_rect = self.option_image.get_rect()
示例4: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import __init__ [as 别名]
def __init__(self, disp_res, fb_res, flags=HWSURFACE|DOUBLEBUF|RESIZABLE,
fps=60, scale_type='pixelperfect', scale_smooth=False, bgcolor=(0,0,0)):
screen = display.set_mode(disp_res, flags)
Surface.__init__(self, fb_res, flags)
self._scale_type = scale_type
self._scale_function = transform.smoothscale if scale_smooth else transform.scale
self.bgcolor = bgcolor
self.compute_target_subsurf()
self._update_rects = []
self._clock = time.Clock()
self._fps = fps
self._lag = 0
self._tdelta = 0
if FrameBuffer.instance is None:
FrameBuffer.instance = self
示例5: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import __init__ [as 别名]
def __init__ (self, size):
Surface.__init__(self, size)
self.fill((50,50,50))
示例6: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import __init__ [as 别名]
def __init__ (self, width, height, alpha=255):
Surface.__init__ (self, (width, height), SRCALPHA, 32)
self._alpha = 255
self._step = -1
self.set_alpha (alpha)
示例7: __init__
# 需要导入模块: from pygame import Surface [as 别名]
# 或者: from pygame.Surface import __init__ [as 别名]
def __init__(self, dim, relXOff, relYOff):
Surface.__init__(self, dim, SRCALPHA)
self.xOff = glob.Screen.WIDTH * 0.5 + relXOff
self.yOff = glob.Screen.HEIGHT * 0.5 + relYOff