当前位置: 首页>>代码示例>>Python>>正文


Python EbGraphicTileset.clear_tile方法代码示例

本文整理汇总了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
开发者ID:LittleCube13,项目名称:CoilSnake,代码行数:55,代码来源:fonts.py


注:本文中的coilsnake.model.eb.graphics.EbGraphicTileset.clear_tile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。