本文整理汇总了Python中event_manager.EventManager.remove方法的典型用法代码示例。如果您正苦于以下问题:Python EventManager.remove方法的具体用法?Python EventManager.remove怎么用?Python EventManager.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event_manager.EventManager
的用法示例。
在下文中一共展示了EventManager.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from event_manager import EventManager [as 别名]
# 或者: from event_manager.EventManager import remove [as 别名]
class Scenario:
def __init__(self, background=None):
if background!=None:
self.set_background(background)
self.event_manager = EventManager()
self.subscribe(pygame.QUIT, "quit", self)
self.items = pygame.sprite.Group()
def set_background(self, background):
self.background = pygame.image.load(background)
self.size = self.background.get_size()
self.surface = pygame.display.set_mode(self.size)
self.backgroundRect = self.background.get_rect()
self.set_limits( (0, 0, self.size[0], self.size[1]))
def set_limits(self, limits):
self.limits = limits
def add(self, item):
self.items.add(item)
Logger.log_debug("Added "+ str(item))
def remove(self, item):
self.items.remove(item)
Logger.log_debug("Removed "+ str(item))
def render(self):
self.surface.blit(self.background, self.backgroundRect)
self.items.draw(self.surface)
pygame.display.flip()
def subscribe(self, event, action, handler):
self.event_manager.add(event, action, handler)
Logger.log_debug("Event "+str(event)+" subscribed "+str(handler)+"#"+str(action))
def unsubscribe(self, event, action, handler):
self.event_manager.remove(event, action, handler)
Logger.log_debug("Event "+str(event)+" unsubscribed "+str(handler)+"#"+str(action))
def post_event(self, code, info):
pygame.event.post(pygame.event.Event(code, info))
def update(self):
self.event_manager.handle(pygame.event.get())
self.items.update()
def quit(self, event):
pygame.quit()
sys.exit()
def position_allowed(self, item, position):
half_size = (item.get_size()[0]/2, item.get_size()[1]/2)
if position[0] - half_size[0] < self.limits[0]:
return False
if position[1] - half_size[0] < self.limits[1]:
return False
if position[0] + half_size[0] > self.limits[2]:
return False
if position[1] + half_size[1] > self.limits[3]:
return False
return True