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


Python Surface.copy方法代码示例

本文整理汇总了Python中pygame.surface.Surface.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.copy方法的具体用法?Python Surface.copy怎么用?Python Surface.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.surface.Surface的用法示例。


在下文中一共展示了Surface.copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaseScreen

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import copy [as 别名]
class BaseScreen():
    """ Base Class Screen.

    Use to manage screen of games
    Use for exec main_loop, update screen.
    Enable to switch screen easier.
    Example :
    +------+         +------+
    | Game |  <----> | Menu |
    +------+         +------+
       ^^
       ||
       vv
    +-------+
    | Pause |
    +-------+
    
    Raise a ChangeScreenException to change screen.
    """
    def __init__(self, width, height, background=None):
        """ Init of baseScreen.
        
        Save the background :
        -  BEFORE init_entities_before ( sprite )
        -  AFTER init_entities_after 
           (Attach entities or text to background)
        so init_entities save elements with background
        init_entities
        """
        self.surface = Surface((width, height))        
        if background is not None:
            self.surface.blit(background, background.get_rect())
        self.init_entities_before(self.surface)
        self.background = self.surface.copy()
        self.init_entities_after(self.surface)

    def init_entities_after(self, surface):
        """ Create entities after saving background.

        Need to be redefined"""
        pass

    def init_entities_before(self, surface):
        """ Create entities before saving background.

        Need to be redefined"""
        pass
    
    def main_loop(self):
        """ Function to use in main loop.
        
        Return update list of coordinates to refresh.
        """       
        self.execute(self.surface)
        self.erase_all_map()
        return self.draw(self.surface)
    
    def execute(self, surface):
        """ Exec and Update entities of the screen.

        Need to be redefined.
        """ 
        pass
    
    def erase_all_map(self):
        """ Erase all background

        Can redefine this function
        """
        self.surface = self.background.copy()
        
    def draw(self, surface):
        """ Draw entities in the surface.

        Need to be redefined.
        """
        pass
开发者ID:Bobbyshow,项目名称:Bslib,代码行数:79,代码来源:base_screen.py


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