本文整理汇总了Python中texture.Texture.setFromSurface方法的典型用法代码示例。如果您正苦于以下问题:Python Texture.setFromSurface方法的具体用法?Python Texture.setFromSurface怎么用?Python Texture.setFromSurface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类texture.Texture
的用法示例。
在下文中一共展示了Texture.setFromSurface方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import setFromSurface [as 别名]
def __init__(self, font_file):
self._glyphs = {}
self._kern = {}
self._page = {}
if "." not in font_file:
font_file = font_file+".zip"
with zipfile.ZipFile(font_file,'r') as z:
if font_file.lower().endswith(".zip"):
font_file = os.path.basename(font_file)[:-4]
xml = z.read(font_file+".fnt")
xroot = ET.fromstring(xml)
# misc info
com = xroot.find('common')
self._line_height = int(com.get("lineHeight"))
self._base = int(com.get("base"))
self._imgw = int(com.get("scaleW"))
self._imgh = int(com.get("scaleH"))
# load the textures
for page in xroot.find('pages').findall("page"):
id = int(page.get("id"))
img_filename = page.get("file")
img = z.read(img_filename)
surf = pygame.image.load(StringIO.StringIO(img),img_filename)
tex = Texture()
tex.setFromSurface(surf)
self._page[id] = tex
assert(id == 0) # for now, we only support single-page fonts
# load the glyph data
for char in xroot.find("chars").findall("char"):
d = {}
for f in self.Glyph._fields:
d[f] = int(char.get(f))
g=self.Glyph(**d)
self._glyphs[g.id] = g
# load the kerning data
for kern in xroot.find("kernings").findall("kerning"):
t = (int(kern.get("first")), int(kern.get("second")))
self._kern[t] = int(kern.get("amount"))
self._material = Material()
self._material.setTexture(0,self._page[0])