本文整理汇总了Python中view.View.setCenter方法的典型用法代码示例。如果您正苦于以下问题:Python View.setCenter方法的具体用法?Python View.setCenter怎么用?Python View.setCenter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类view.View
的用法示例。
在下文中一共展示了View.setCenter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import setCenter [as 别名]
class Game() :
def __init__(self, windowLabel = "My game", tileSize = 32) :
# Initialize PyGame
pygame.init()
# Set up FPS clock
self.fps = 30
self.fpsClock = pygame.time.Clock()
# Setup a view
self.view = View(windowLabel, tileSize, (16,16))
self.tileSize = tileSize
def setMap(self, map) :
self.map = map
def setHero(self, hero) :
self.hero = hero
self.hero.walkabilityChecker = self.map.getWalkability
self.hero.getObject = self.map.getObject
def mainLoop(self) :
# Handle events
self.eventHandler()
# Handle keys
self.keysHandler()
# Update character
self.hero.update()
# Center the view on hero
self.view.setCenter((self.hero.x, self.hero.y))
# Render elements
self.view.render(self.map, self.hero)
# Update screen
pygame.display.update()
self.fpsClock.tick(self.fps)
def eventHandler(self) :
for event in pygame.event.get():
if (event.type == pygame.QUIT) :
pygame.quit()
sys.exit()
def keysHandler(self) :
keyPressed = pygame.key.get_pressed()
moveDirection = ""
if (keyPressed[pygame.K_UP]) : moveDirection = "back"
if (keyPressed[pygame.K_DOWN]) : moveDirection = "front"
if (keyPressed[pygame.K_LEFT]) : moveDirection = "left"
if (keyPressed[pygame.K_RIGHT]) : moveDirection = "right"
if (moveDirection != "") :
self.hero.look(moveDirection)
self.hero.move(moveDirection)
if (keyPressed[pygame.K_e]) :
self.hero.actionKeyHandler();