本文整理汇总了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