本文整理匯總了Python中coilsnake.model.eb.graphics.EbGraphicTileset.clear_tile方法的典型用法代碼示例。如果您正苦於以下問題:Python EbGraphicTileset.clear_tile方法的具體用法?Python EbGraphicTileset.clear_tile怎麽用?Python EbGraphicTileset.clear_tile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類coilsnake.model.eb.graphics.EbGraphicTileset
的用法示例。
在下文中一共展示了EbGraphicTileset.clear_tile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: EbFont
# 需要導入模塊: from coilsnake.model.eb.graphics import EbGraphicTileset [as 別名]
# 或者: from coilsnake.model.eb.graphics.EbGraphicTileset import clear_tile [as 別名]
class EbFont(object):
def __init__(self, num_characters=96, tile_width=16, tile_height=8):
self.num_characters = num_characters
self.tileset = EbGraphicTileset(num_tiles=num_characters, tile_width=tile_width, tile_height=tile_height)
self.character_widths = None
def from_block(self, block, tileset_offset, character_widths_offset):
self.tileset.from_block(block=block, offset=tileset_offset, bpp=1)
for i in range(96, self.num_characters):
self.tileset.clear_tile(i, color=1)
self.character_widths = block[character_widths_offset:character_widths_offset + self.num_characters].to_list()
def to_block(self, block):
tileset_offset = block.allocate(size=self.tileset.block_size(bpp=1))
self.tileset.to_block(block=block, offset=tileset_offset, bpp=1)
character_widths_offset = block.allocate(size=self.num_characters)
block[character_widths_offset:character_widths_offset + self.num_characters] = self.character_widths
return tileset_offset, character_widths_offset
def to_files(self, image_file, widths_file, image_format="png", widths_format="yml"):
if self.num_characters == 96:
image = _FONT_IMAGE_ARRANGEMENT_96.image(self.tileset, FONT_IMAGE_PALETTE)
elif self.num_characters == 128:
image = _FONT_IMAGE_ARRANGEMENT_128.image(self.tileset, FONT_IMAGE_PALETTE)
image.save(image_file, image_format)
del image
character_widths_dict = dict(enumerate(self.character_widths))
if widths_format == "yml":
yml_dump(character_widths_dict, widths_file, default_flow_style=False)
def from_files(self, image_file, widths_file, image_format="png", widths_format="yml"):
image = open_indexed_image(image_file)
if self.num_characters == 96:
self.tileset.from_image(image, _FONT_IMAGE_ARRANGEMENT_96, FONT_IMAGE_PALETTE)
elif self.num_characters == 128:
self.tileset.from_image(image, _FONT_IMAGE_ARRANGEMENT_128, FONT_IMAGE_PALETTE)
del image
if widths_format == "yml":
widths_dict = yml_load(widths_file)
self.character_widths = [widths_dict[i] for i in range(self.tileset.num_tiles_maximum)]
def image_size(self):
if self.num_characters == 96:
arr = _FONT_IMAGE_ARRANGEMENT_96
elif self.num_characters == 128:
arr = _FONT_IMAGE_ARRANGEMENT_128
return arr.width * self.tileset.tile_width, arr.height * self.tileset.tile_height