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


Python Font.render方法代码示例

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


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

示例1: main

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
def main():
    """Main program loop"""
    
    pygame.init()
    screen = pygame.display.set_mode(opt.window_size)
    
    sys_font = Font(get_default_font(), opt.font_size)
    clock = Clock()
    
    manager = YarsManager()

    running = True
    
    while running:
        #limit framerate and prepare FPS display text
        clock.tick(opt.max_framerate)
        fps = clock.get_fps()
        fps_text = sys_font.render("FPS: {0:.1f}".format(fps), False, opt.white)
        
        if event.get(pygame.QUIT):
            sys.exit()

        running = manager.handle_events(event.get(), key.get_pressed())
        manager.update()

        screen.fill(opt.black)
        manager.draw(screen)
        screen.blit(fps_text, fps_text.get_rect(top = 0, right = opt.width))
        pygame.display.update()
		
    sys.exit()
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:33,代码来源:game.py

示例2: __init__

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
    def __init__(self, x, y, width, height, msg, size=16, 
            text_colour=base.BLACK, bg_colour=base.WHITE, 
            highlight_text=base.WHITE, highlight_bg=base.BLACK,
            offset_x=0, offset_y=0, bold=False):

        self.normal = pygame.Surface((width, height))
        self.normal.fill(bg_colour)

        font = Font(_FONT, size)
        font.set_bold(bold)
        font_width, font_height = font.size(msg)
        font_x = (width - font_width) / 2
        font_y = (height - font_height) / 2

        self.normal.blit(font.render(msg, False, text_colour), 
                                    (font_x, font_y))

        self.highlighted = pygame.Surface((width, height))
        self.highlighted.fill(highlight_bg)
        self.highlighted.blit(font.render(msg, False, highlight_text), 
                                        (font_x, font_y))

        self.offset_x = offset_x
        self.offset_y = offset_y
        
        self.force_highlight = False
        self.disabled = False
        PicassoAsset.__init__(self, self.normal, x, y)
开发者ID:anthony-cervantes,项目名称:risk-1,代码行数:30,代码来源:clickable.py

示例3: LcarsText

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
class LcarsText(LcarsWidget):
    def __init__(self, colour, pos, message, size=1.0,
                 background=None, resolution=(480, 320)):
        self.colour = colour
        self.message = message
        self.background = background
        script_dir = dirname(__file__)
        ipath = join(script_dir, '../../assets/swiss911.ttf')
        self.font = Font(ipath, int(19.0 * size))

        self.renderText(message)
        # center the text if needed
        if (pos[1] < 0):
            # Screen specific magic number below! 240 = half width
            pos = (pos[0], resolution[0]/2 - self.image.get_rect().width/2)

        LcarsWidget.__init__(self, colour, pos, None)

    def renderText(self, message):
        if (self.background is None):
            self.image = self.font.render(message, True, self.colour)
        else:
            self.image = self.font.render(message, True,
                                          self.colour, self.background)

    def setText(self, newText):
        self.message = newText
        self.renderText(newText)

    def changeColour(self, colour):
        self.colour = colour
        self.renderText(self.message)
开发者ID:astrobokonon,项目名称:rpi_lcars,代码行数:34,代码来源:lcars_widgets.py

示例4: __init__

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
    def __init__(self, manager):
        GameState.__init__(self, manager)

        sys_font = Font(get_default_font(), options.font_size)
        self.message1 = sys_font.render("Andrew's Bitchin' Yars' Revenge Clone",
                                        True, options.white)
        self.message2 = sys_font.render("Press shoot button (space) to start.",
                                        True, options.white)
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:10,代码来源:title.py

示例5: __init__

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
class Menu:
	def __init__(self, x, y, fontsize, space, color_fg, color_bg, background, titles):
		self.titles = titles
		self.images = []
		self.rects = []
		self.himages = []
		self.color_fg = color_fg
		self.color_bg = color_bg
		self.space = space
		self.background = data.load_image(background)
		self.index = 0
		self.x = x
		self.y = y
		self.font = Font(data.filepath('fonts', 'vera.ttf'), fontsize)
		self.font.set_bold(True)
		self.fonth = Font(data.filepath('fonts', 'vera.ttf'), fontsize+5)
		self.fonth.set_bold(True)
		
	def init(self):
		
		dy = 0
		for title in self.titles:
			image = self.font.render(title, True, self.color_bg)
			himage = self.fonth.render(title, True, self.color_fg)
			rect = image.get_rect()
			rect.move_ip(self.x, self.y + dy)
			dy += rect.height + self.space
			self.images.append(image)
			self.himages.append(himage)
			self.rects.append(rect)
				
	def run(self, screen):
		def blit(screen):
			screen.blit(self.background, (0,0))
			for image, rect in zip(self.images, self.rects):
				if image != self.images[self.index]:
					screen.blit(image, rect)
			screen.blit(self.himages[self.index], self.rects[self.index])
			pygame.display.update()
		
		done = False
		blit(screen)
		while not done:
			for event in pygame.event.get():
				if event.type == QUIT:
					sys.quit()
				if event.type == KEYDOWN:
					if event.key == K_DOWN:
						self.index = min(self.index+1, len(self.images)-1)
						blit(screen)
					if event.key == K_UP:
						self.index = max(self.index-1, 0)
						blit(screen)
					if event.key == K_RETURN:
						done = True
		return self.index
开发者ID:ceronman,项目名称:twsitemall,代码行数:58,代码来源:application.py

示例6: TextBar

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
class TextBar(Sprite):
    def __init__(self, text, rect, fontSize):
        Sprite.__init__(self)
        self.font = Font(None, fontSize)
        self.rect = Rect(rect)
        self.image = pygame.surface.Surface((rect[2],
                                             rect[3]))
        self.image = self.font.render(text, 0, TEXTCOLOR)
    def setText(self, text):
        self.image = self.font.render(text, 0, TEXTCOLOR)
开发者ID:bry,项目名称:pybomber2,代码行数:12,代码来源:windows.py

示例7: __init__

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
    def __init__(self, x, y, width, height, msg, size=32, 
            text_colour=base.BLACK, bg_colour=base.WHITE, 
            highlight_text=base.WHITE, highlight_bg=base.BLACK):

        font = Font(None, size)
        self.normal = pygame.Surface((width, height))
        self.normal.fill(bg_colour)
        self.normal.blit(font.render(msg, False, text_colour), (0, 0))
    
        self.highlighted = pygame.Surface((width, height))
        self.highlighted.fill(highlight_bg)
        self.highlighted.blit(font.render(msg, False, highlight_text), (0, 0))
        PicassoAsset.__init__(self, self.normal, x, y)
开发者ID:B-Lock,项目名称:risk,代码行数:15,代码来源:clickable.py

示例8: main

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
def main():
    """The main function of the game.
    Initializes PyGame objects and then enters the game loop
    """
    
    pygame.init()
    screen = pygame.display.set_mode(window_size)
    
    sys_font = Font(get_default_font(), font_size)
    clock = Clock()
    
    #now that pygame is initialized, initialize inherited classes properly
    global enemy_wave, player
    enemy_wave = EnemyGroup(evil_bullets)
    
    player = Player(window_size, ship_filename, ship_speed)
    
    while 1:
        #limit framerate and prepare FPS display text
        clock.tick(max_framerate)
        fps = clock.get_fps()
        fps_text = sys_font.render("FPS: {0:.1f}".format(fps), False, white)
        
        score_text = sys_font.render("SCORE: {}".format(score), False, white)
        lives_text = sys_font.render("MANS: {}".format(lives), False, white)
    
        #check for QUIT event to prevent endless loopage
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()
            
        #call the game's thinking functions
        check_gameover()
        keyboard()
        evil_bullets.update()
        good_bullets.update()
        enemy_wave.update()
        collisions()
            
        #draw the stuff
        screen.fill(black)
        good_bullets.draw(screen)
        evil_bullets.draw(screen)
        enemy_wave.draw(screen)
        screen.blit(player.image, player.rect)
        screen.blit(score_text, score_text.get_rect(top = 0, left = 0))
        screen.blit(lives_text, lives_text.get_rect(top = 0, centerx = width / 2))
        screen.blit(fps_text, fps_text.get_rect(top = 0, right = width))
        pygame.display.update()
开发者ID:rubiximus,项目名称:invader-shootan,代码行数:50,代码来源:game.py

示例9: MenuScreen

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
class MenuScreen(BaseScreen):

    def init_entities_before(self, surface):
        self.font = Font(None, 30)
        self.textImg = self.font.render(
            'Press SPACE to BEGIN !',
            1,
            (255,255,255)
        )
        surface.blit(self.textImg, (200,200))

    def execute(self, surface):
        if pygame.key.get_pressed()[SPACE] == 1:
            raise ChangeScreenException(1, 'Launch the game!')

    def erase_all_map(self):
        pass

    def draw(self, surface):
        pass
    
    def game_over(self, text, number=None):
        BaseScreen.erase_all_map(self)
        font = Font(None, 30)
        textImg = font.render(text, 1, (255,255,255))
        self.surface.blit(textImg, (200,100))
开发者ID:Bobbyshow,项目名称:Avoid,代码行数:28,代码来源:menu.py

示例10: __init__

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
    def __init__(self, manager, score, lives, next_state):
        GameState.__init__(self, manager)

        sys_font = Font(get_default_font(), options.font_size)
        self.score_text = sys_font.render(str(score), True, options.white)
        self.lives_text = sys_font.render(str(lives), True, options.white)

        self.next_state = next_state
开发者ID:rubiximus,项目名称:yars-revenge,代码行数:10,代码来源:infoscreen.py

示例11: TextInput

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
class TextInput(Sprite):
    """
    >>> import pygame
    >>> from color_picker import *
    >>> pygame.font.init()

    Set text
    >>> text = "Hello World!"
    >>> testRect = Rect((0,0),(20,20))
    >>> theInput = TextInput(text, testRect)
    >>> theInput.getText()
    'Hello World!'

    Add a character to a string
    >>> theInput.appendChar(103)
    >>> theInput.getText()
    'Hello World!g'

    Delete a character from a string
    >>> theInput.deleteChar()
    >>> theInput.getText()
    'Hello World!'
    """

    def __init__(self, text, rect, fontSize):
        Sprite.__init__(self)
        self.font = Font(None, fontSize)
        self.text = text
        self.rect = Rect(rect)
        self.image = self.font.render(text, 0, TEXTCOLOR2)

    def getText(self):
        return self.text

    def setText(self, text):
        self.text = text
        self.image = self.font.render(self.text, 0, TEXTCOLOR2)

    def appendChar(self, char):
        self.text = self.text + chr(char)
        self.image = self.font.render(self.text, 0, TEXTCOLOR2)
        
    def deleteChar(self):
        self.text = self.text[0:-1]
        self.image = self.font.render(self.text, 0, TEXTCOLOR2)
开发者ID:bry,项目名称:pybomber2,代码行数:47,代码来源:windows.py

示例12: render_text

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
 def render_text(self, msg):
     font = Font(_FONT, self.size)
     font.set_bold(self.bold)
     new_surface = pygame.Surface((self.width, self.height), 
                     pygame.SRCALPHA, 32)
     msg = msg.strip("\n")
     lines = msg.split("\n")
     longest = max(lines, key=lambda x: len(x))
     
     #new_surface = pygame.Surface((self.width, self.height))
     temp_surface = font.render(longest, False, self.colour)
     msg_width = temp_surface.get_size()[0]
     msg_height = font.get_height() * len(lines)
     msg_x = (new_surface.get_width() - msg_width) / 2
     msg_y = (new_surface.get_height() - msg_height) / 2
     for index, line in enumerate(lines):
         font_surface = font.render(line, False, self.colour)
         new_surface.blit(font_surface, (msg_x, 
                 msg_y + (font.get_height() * index)))
     self.surface = new_surface
开发者ID:anthony-cervantes,项目名称:risk-1,代码行数:22,代码来源:text.py

示例13: display_message

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
	def display_message(screen, msg, x_center_delta=0, y_center_delta=0):
		center_x = (Helpers.const["size"]["display_width"] / 2) + x_center_delta
		center_y = (Helpers.const["size"]["display_height"] / 2) + y_center_delta
		msg_font =  Font(None, 30)

		screen_text = msg_font.render(msg, True, Helpers.const["color"]["white"])
		text_rect = screen_text.get_rect()
		text_rect.center = (center_x, center_y)
		
		screen.blit(screen_text, text_rect)
		pygame.display.update(text_rect)
		return text_rect
开发者ID:tsvetelina-aleksandrova,项目名称:Spacekatz,代码行数:14,代码来源:helpers.py

示例14: LcarsText

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
class LcarsText(LcarsWidget):
    def __init__(self, colour, pos, message, size=1.0, background=None):
        self.colour = colour
        self.background = background
        self.font = Font("assets/swiss911.ttf", int(19.0 * size))
        
        self.renderText(message)
        # center the text if needed 
        if (pos[1] < 0):
            pos = (pos[0], 400 - self.image.get_rect().width / 2)
            
        LcarsWidget.__init__(self, colour, pos, None)

    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)
        
    def setText(self, newText):
        self.renderText(newText)
开发者ID:elijaheac,项目名称:rpi_lcars,代码行数:23,代码来源:lcars_widgets.py

示例15: draw_mouse_info

# 需要导入模块: from pygame.font import Font [as 别名]
# 或者: from pygame.font.Font import render [as 别名]
 def draw_mouse_info(self, message, drawing=False):
     # Empty mouse canvas
     self.mouse_info_canvas.fill(self.background_color)
     
     # Create font and blit onto canvas
     font = Font(None, 22)
     mouse_info = font.render(message, 1, Colour.CHOCOLATE, Colour.BLACK)
     self.mouse_info_canvas.blit(mouse_info, (self.mouse_info_x, self.mouse_info_y))
     
     # If Mouse is dragging, notify
     if drawing:
         ti = Font(None, 30).render("DRAWING",1,Colour.CHOCOLATE, Colour.BLACK)
         self.mouse_info_canvas.blit(ti, (self.mouse_info_x, self.mouse_info_y+20))
开发者ID:parhamfh,项目名称:muscovaudio,代码行数:15,代码来源:canvas.py


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