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


Python pygame.font方法代码示例

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


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

示例1: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def __init__(self, colour, pos, text, handler=None, rectSize=None):
        if rectSize == None:
            image = pygame.image.load("assets/button.png").convert_alpha()
            size = (image.get_rect().width, image.get_rect().height)
        else:
            size = rectSize
            image = pygame.Surface(rectSize).convert_alpha()
            image.fill(colour)

        self.colour = colour
        self.image = image
        font = Font("assets/swiss911.ttf", 19)
        textImage = font.render(text, False, colours.BLACK)
        image.blit(textImage, 
                (image.get_rect().width - textImage.get_rect().width - 10,
                    image.get_rect().height - textImage.get_rect().height - 5))
    
        LcarsWidget.__init__(self, colour, pos, size, handler)
        self.applyColour(colour)
        self.highlighted = False
        self.beep = Sound("assets/audio/panel/202.wav") 
开发者ID:tobykurien,项目名称:rpi_lcars,代码行数:23,代码来源:lcars_widgets.py

示例2: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def __init__(self, ai_settings: Settings, stats: GameStats, screen: pygame.SurfaceType):

        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.ai_settings = ai_settings
        self.stats = stats
        self.score_ship_size = self.ai_settings.score_ship_size  # size of ship in the scoreboard.
        self.dur_highscore_msg = 3000        # duration of highscore msg = 3 sec

        # Font settings.
        font_name = 'fonts/PoiretOne.ttf'       # try changing the font
        self.font_color = self.ai_settings.score_font_color
        self.font = pygame.font.Font(font_name, self.ai_settings.score_font_size)

        # Prepare the initial score image.
        self.prep_images() 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:18,代码来源:scorecard.py

示例3: prep_high_score

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def prep_high_score(self):
        """Prepare the high score."""
        high_score = round(self.stats.high_score, -1)
        high_score_str = "High Score: {:,}".format(high_score)

        self.high_score_image = self.font.render(high_score_str, True, self.font_color)

        self.high_score_rect = self.high_score_image.get_rect()
        self.high_score_rect.top = self.score_rect.top
        self.high_score_rect.centerx = self.screen_rect.centerx

        self.new_high_score_msg = "Congratulations! New High Score."
        self.new_high_score_image = self.font.render(self.new_high_score_msg, True, self.font_color)
        self.new_high_score_rect = self.new_high_score_image.get_rect()
        self.new_high_score_rect.centerx = self.high_score_rect.centerx
        self.new_high_score_rect.y = self.high_score_rect.bottom + 4 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:18,代码来源:scorecard.py

示例4: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def __init__(self, colour, pos, text, handler=None):
        self.handler = handler
        image = pygame.image.load("assets/button.png").convert()
        size = (image.get_rect().width, image.get_rect().height)
        font = Font("assets/swiss911.ttf", 19)
        textImage = font.render(text, False, colours.BLACK)
        image.blit(textImage, 
                   (image.get_rect().width - textImage.get_rect().width - 10,
                    image.get_rect().height - textImage.get_rect().height - 5))

        self.image = image
        self.colour = colour
        LcarsWidget.__init__(self, colour, pos, size)
        self.applyColour(colour)
        self.highlighted = False
        self.beep = Sound("assets/audio/panel/202.wav") 
开发者ID:tobykurien,项目名称:pi-tracking-telescope,代码行数:18,代码来源:lcars_widgets.py

示例5: checkdependencies

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def checkdependencies():
    "only returns if everything looks ok"
    msgs = []

    #make sure this looks like the right directory
    if not os.path.isdir(CODEDIR):
        msgs.append('Cannot locate stuntcat modules')
    if not os.path.isdir('data'):
        msgs.append('Cannot locate stuntcat data files')

    #first, we need python >= 2.7
    if sys.hexversion < 0x2070000:
        errorbox('Requires Python-2.7 or Greater')

    #is correct pg found?
    try:
        import pygame as pg
        if pg.ver < '1.9.4':
            msgs.append('Requires pygame 1.9.4 or Greater, You Have ' + pg.ver)
    except ImportError:
        msgs.append("Cannot import pygame, install version 1.9.4 or higher")
        pg = None

    #check that we have FONT and IMAGE
    if pg:
        if not pg.font:
            msgs.append('pg requires the SDL_ttf library, not available')
        if not pg.image or not pg.image.get_extended():
            msgs.append('pg requires the SDL_image library, not available')

    if msgs:
        msg = '\n'.join(msgs)
        errorbox(msg)



#Pretty Error Handling Code... 
开发者ID:pygame,项目名称:stuntcat,代码行数:39,代码来源:cli.py

示例6: displayMessage

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def displayMessage( message, screen, background ):
   font = pygame.font.Font( None, 48 )
   text = font.render( message, 1, ( 250, 250, 250 ) )
   textPosition = text.get_rect()
   textPosition.centerx = background.get_rect().centerx
   textPosition.centery = background.get_rect().centery
   return screen.blit( text, textPosition )

# remove outdated time display and place updated time on screen 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:11,代码来源:fig24_06.py

示例7: updateClock

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def updateClock( time, screen, background, oldPosition ):
   remove = screen.blit( background, oldPosition, oldPosition )
   font = pygame.font.Font( None, 48 )
   text = font.render( str( time ), 1, ( 250, 250, 250 ),
      ( 0, 0, 0 ) )
   textPosition = text.get_rect()
   post = screen.blit( text, textPosition )
   return remove, post 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:10,代码来源:fig24_06.py

示例8: render_text

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def render_text(text, window, font, color, position):
    """Renders a font and blits it to the given window"""
    text = font.render(text, 1, color)

    window.blit(text, position)

    return text 
开发者ID:buntine,项目名称:SwervinMervin,代码行数:9,代码来源:util.py

示例9: __pgbox

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def __pgbox(title, message):
    try:
        import pygame as pg
        pg.quit() #clean out anything running
        pg.display.init()
        pg.font.init()
        screen = pg.display.set_mode((460, 140))
        pg.display.set_caption(title)
        font = pg.font.Font(None, 18)
        foreg, backg, liteg = (0, 0, 0), (180, 180, 180), (210, 210, 210)
        ok = font.render('Ok', 1, foreg, liteg)
        okbox = ok.get_rect().inflate(200, 10)
        okbox.centerx = screen.get_rect().centerx
        okbox.bottom = screen.get_rect().bottom - 10
        screen.fill(backg)
        screen.fill(liteg, okbox)
        screen.blit(ok, okbox.inflate(-200, -10))
        pos = [10, 10]
        for text in message.split('\n'):
            if text:
                msg = font.render(text, 1, foreg, backg)
                screen.blit(msg, pos)
            pos[1] += font.get_height()
        pg.display.flip()
        stopkeys = pg.K_ESCAPE, pg.K_SPACE, pg.K_RETURN, pg.K_KP_ENTER
        while 1:
            e = pg.event.wait()
            if e.type == pg.QUIT or \
                       (e.type == pg.KEYDOWN and e.key in stopkeys) or \
                       (e.type == pg.MOUSEBUTTONDOWN and okbox.collidepoint(e.pos)):
                break
        pg.quit()
    except pg.error:
        raise ImportError 
开发者ID:pygame,项目名称:stuntcat,代码行数:36,代码来源:cli.py

示例10: prep_score

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def prep_score(self):
        """Prepare the image of score."""
        rounded_score = round(self.stats.score, -1)
        score_str = "{:,}".format(rounded_score)

        self.score_image = self.font.render(score_str, True, self.font_color)

        self.score_rect = self.score_image.get_rect()
        self.score_rect.top = 10
        self.score_rect.right = self.screen_rect.right - 20 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:12,代码来源:scorecard.py

示例11: prep_level

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def prep_level(self):
        """Prepare the image of current level."""
        level_str = "Level: {:d}".format(self.stats.level)
        self.level_image = self.font.render(level_str, True, self.font_color)
        self.level_rect = self.level_image.get_rect()
        self.level_rect.top = self.score_rect.top + 45
        self.level_rect.right = self.score_rect.right 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:9,代码来源:scorecard.py

示例12: prep_ships

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def prep_ships(self):
        """Show how many ships are left."""
        ship_str = "Ships left:  " if self.stats.ships_left > 0 else "No ships left."
        self.ship_str_image = self.font.render(ship_str, True, self.font_color)
        self.ship_str_rect = self.ship_str_image.get_rect()
        self.ship_str_rect.x = 10
        self.ship_str_rect.y = self.score_rect.top

        self.ships = Group()
        for ship_number in range(self.stats.ships_left):
            ship = Ship(self.ai_settings, self.screen, self.score_ship_size)
            ship.rect.x = self.ship_str_rect.width + ship_number * ship.rect.width
            ship.rect.centery = self.ship_str_rect.centery
            self.ships.add(ship) 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:16,代码来源:scorecard.py

示例13: _load

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def _load(self, path, fontsize=None):
        return pygame.font.Font(path, fontsize) 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:4,代码来源:loaders.py

示例14: renderText

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def renderText(self, message):        
        if (self.background == None):
            self.image = self.font.render(message, True, self.colour)
        else:
            self.image = self.font.render(message, True, self.colour, self.background) 
开发者ID:tobykurien,项目名称:pi-tracking-telescope,代码行数:7,代码来源:lcars_widgets.py

示例15: text

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import font [as 别名]
def text(x, y, text, size, color, font = None, antialias = False):
	x=int(x)
	y=int(y)
	global surfarr, changed
	changed = True
	if font is None:
		font = pygame.font.SysFont("", size)
	else:
		font = pygame.font.Font(font, size)
	surface = font.render(text, antialias, color)
	del surfarr
	background.blit(surface, (x,y))
	surfarr = pygame.PixelArray(background) 
开发者ID:yaksok,项目名称:yaksok,代码行数:15,代码来源:simplecanvas.py


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