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


Python Surface.blit方法代码示例

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


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

示例1: update

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
    def update(self, duration):
        """ update all the contained linewidgets
        TODO: check that it works with transparent bg
        """

        if self.dirty == 0:
            return

        # make the box
        size = self.rect.size
        bgcol = self.bgcolor
        if bgcol:  # only display a bg img if bgcolor specified
            img = Surface(size)
            img.fill(bgcol)
            img = img.convert()
        else:  # more or less transparent
            img = Surface(size, SRCALPHA)  # handles transparency
            transparency = 50  # 0 = transparent, 255 = opaque
            img.fill((0, 0, 0, transparency))
            img = img.convert_alpha()

        # blit each line
        numelemts = min(len(self.texts), self.maxnumlines)
        for i in range(numelemts):
            wid = self.linewidgets[i]
            wid.set_text(self.texts[-i - 1])
            wid.update(duration)
            img.blit(wid.image, wid.rect)

        self.image = img
开发者ID:gentimouton,项目名称:crowd-control,代码行数:32,代码来源:widgets.py

示例2: prepare_paragraph

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
def prepare_paragraph(text, width, size="normal", colour=(0,0,0)):
    font = FONTS[size]
    lines = []
    words = text.split()
    if words:
        lastline = None
        line = words[0]
        for i in range(1,len(words)):
            lastline = line
            line = line+" "+words[i]
            w,h = font.size(line)
            if w > width:
                lines.append(lastline)
                line = words[i]
    else:
        line = ""
    lines.append(line)

    parawidth = max(font.size(each)[0] for each in lines)
    lineheight = font.get_height()
    paraheight = lineheight*len(lines)
    paragraph = Surface((parawidth,paraheight),pygame.SRCALPHA)
    paragraph.fill((255,255,255,0))
    for y,line in enumerate(lines):
        text = prepare(line,size,colour)
        paragraph.blit(text,(0,y*lineheight))
    return paragraph
开发者ID:scavpy,项目名称:Scav-Threads-PyWeek-Sep-2012,代码行数:29,代码来源:typefaces.py

示例3: __init__

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
 def __init__(self, fruit, interp_step):
     """ Prepare the fruit's spr: a square diamond 
     with a number in the center.
     interp_step determines where to position the sprite, 
     based on the view's current sprite step. 
     """
     DirtySprite.__init__(self)
     self.fruit = fruit
     
     # make the square
     sq_surf = Surface((cell_size / 1.414, cell_size / 1.414))
     sq_surf.set_colorkey((255, 0, 255))  # magenta = color key
     sq_surf.fill(FRUIT_COLORS[fruit.fruit_type])
     # rotate for a diamond
     dm_surf = rotate(sq_surf, 45)
     blit_rect = Rect(0, 0, cell_size * 1.414, cell_size * 1.414)
     # blit the diamond as the fruit's image
     img = Surface((cell_size, cell_size))
     img.set_colorkey((255, 0, 255))  # magenta = color key
     img.fill((255, 0, 255))
     img.blit(dm_surf, blit_rect)
     
     # add text at the center
     self.font = Font(None, font_size) 
     txtsurf = self.font.render(str(fruit.fruit_num), True, (0, 0, 0))
     textpos = txtsurf.get_rect(center=(cell_size / 2, cell_size / 2))
     img.blit(txtsurf, textpos)
     
     # prepare rect to blit on screen
     self.resync(interp_step)
     
     self.image = img
开发者ID:gentimouton,项目名称:smofac,代码行数:34,代码来源:fruitspr.py

示例4: order_reversed_spritesheet

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
    def order_reversed_spritesheet(self, flipped_sheet):
        """Reorganize the frames in a flipped sprite sheet so that
        they are in the same order as the original sheet.

        Args:
            flipped_sheet: A PyGame Surface containing a flipped sprite
                sheet.

        Returns:
            A PyGame Surface containing the sprite sheet with each frame
            flipped and in the correct order.
        """
        ordered_sheet = Surface((self.spritesheet.get_width(),
                                 self.spritesheet.get_height()),
                                SRCALPHA)
        ordered_sheet.convert_alpha()

        for frame_index in xrange(0, self.get_num_of_frames()):
            frame_x = self.get_width() * frame_index
            old_frame_index = self.get_num_of_frames() - 1 - frame_index
            old_region = self.get_frame_region(old_frame_index)

            ordered_sheet.blit(flipped_sheet, (frame_x, 0), old_region)

        return ordered_sheet
开发者ID:MarquisLP,项目名称:Sidewalk-Champion,代码行数:27,代码来源:graphics.py

示例5: prepare_table

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
def prepare_table(rows, alignment="lr", size="normal", colour=(0,0,0), padding=0):
    f = FONTS[size]
    numcolumns = len(rows[0])
    numrows = len(rows)
    def u(n):
        return n if isinstance(n, unicode) else unicode(n)
    shapes = [[f.size(u(col)) for col in row] for row in rows]
    maxheight = max(max(shape[1] for shape in shaperow) for shaperow in shapes)
    widths = [max(shaperow[i][0] for shaperow in shapes) for i in range(numcolumns)]
    table = Surface((sum(widths) + padding * (numcolumns - 1),
                     maxheight * numrows + padding * (numrows - 1)),
                    pygame.SRCALPHA)
    table.fill((255,255,255,0))
    y = 0
    for r, row in enumerate(rows):
        x = 0
        for c, col in enumerate(row):
            w, h = shapes[r][c]
            text = prepare(u(col), size=size, colour=colour)
            align = alignment[c]
            if align == "r":
                adjustx = widths[c] - w
            elif align == "c":
                adjustx = (widths[c] - w) // 2
            else:
                adjustx = 0
            table.blit(text, (x + adjustx, y))
            x += widths[c] + padding
        y += maxheight + padding
    return table
开发者ID:scavpy,项目名称:Scav-Threads-PyWeek-Sep-2012,代码行数:32,代码来源:typefaces.py

示例6: __init__

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
class GameUI:
    def __init__(self, mainchar):
        self.bg = Surface((600, 1600))
        self.statusbar = Surface((200, 600))
        self.mainchar = mainchar
        self.widget = []
        self.create_bg()
    
    def create_bg(self):
        rbg = self.bg.get_rect()
        bgimg = media.load_image('bg.png').convert()
        rbgimg = bgimg.get_rect()
        columns = int(rbg.width / rbgimg.width) + 1
        rows = int(rbg.height / rbgimg.height) + 1
        
        for y in xrange(rows):
            for x in xrange(columns):
                if x == 0 and y > 0:
                    rbgimg = rbgimg.move([-(columns -1 ) * rbgimg.width, rbgimg.height])
                if x > 0:
                    rbgimg = rbgimg.move([rbgimg.width, 0])
                self.bg.blit(bgimg, rbgimg)
                        
    def update(self):
        r = pygame.rect.Rect(0, 0, 200, 100)
        
        for w in self.widget:
            w.update()
            self.statusbar.blit(w.image, r)
            r = r.move((0, 100))
开发者ID:benoxoft,项目名称:pitfairyhunter,代码行数:32,代码来源:ui.py

示例7: menu

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
class menu(object):
    
    def __init__(self, rect, width):
        self.surface = Surface((width, rect.height))
        self.surface.fill((100,100,250))
        self.buttonDict = dict()
        self.addButton(10, 10, 40, 40, "House")
        self.updateAll()
        
    def addButton(self, x, y, width, height, text):
        self.buttonDict[(x, y, width, height)] = (button.button(width, height, text))
        
    def getButton(self, x, y):
        for myRect in self.buttonDict.keys():
            if Rect(myRect[0], myRect[1], myRect[2], myRect[3]).collidepoint(x, y):
                return self.buttonDict[(myRect[0], myRect[1], myRect[2], myRect[3])].text
        return None
            
    def updateAll(self):
        for myRect, button in self.buttonDict.items():
            self.surface.blit(button.surface, (myRect[0], myRect[1]))
    
    def getSurface(self):
        return self.surface
        
开发者ID:rcockbur,项目名称:Python-Game---Dawn,代码行数:26,代码来源:menu.py

示例8: LoadingScene

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
class LoadingScene(AbstractScene):
    """
    @type image: SurfaceType
    @type rect: pygame.rect.RectType
    """

    image = None
    rect = None

    def __init__(self, manager):
        """
        @type manager: slg.application.manager.Manager
        """
        super().__init__(manager)
        self.group = GameSceneGroup(self)
        image = pygame.image.load(os.path.join(GUI_DIR, 'loading_screen.jpg'))
        self.image = Surface(self._manager.get_display().get_size())
        self.rect = pygame.rect.Rect(self.image.get_rect())
        image_size = image.get_size()
        surface_size = self.image.get_size()
        x = int((image_size[0] - surface_size[0]) / 2)
        y = int((image_size[1] - surface_size[1]) / 2)
        if x < 0 and y < 0:
            image = pygame.transform.scale(image, surface_size)
            x, y = 0, 0
        elif x <= 0 <= y:
            image = pygame.transform.scale(image, (surface_size[0], image_size[1]))
            x = 0
        elif y <= 0 <= x:
            image = pygame.transform.scale(image, (image_size[0], surface_size[1]))
            y = 0
        styles = {'font': 'alger', 'font_size': 40, 'align': [TextWidget.CENTER, TextWidget.CENTER]}
        text = TextWidget(**styles)
        text.set_text("""Loading...
Please wait""")
        self.image.blit(image, (-x, -y))
        text.draw(self.image)

    def handle_events(self, events):
        self.group.handle_events(events)
        for e in events:
            if e.type == KEYDOWN:
                self.handle_keypress(e.key, pygame.key.get_mods())

    def handle_keypress(self, key, modificated):
        if key == K_SPACE and self._manager.state < GAME_STATE_LOADING:
            ChangeState(int(not bool(self._manager.state))).post()

        if key == K_m and modificated and pygame.KMOD_CTRL:
            Selector(self._manager.get_display(), self.group)
            ChangeState(GAME_STATE_PAUSED).post()

    def draw(self):
        display_surface = self._manager.get_display()
        display_surface.blit(self.image, (0, 0))
        self.group.update(display_surface)
        self.group.draw(display_surface)
开发者ID:ImmRanneft,项目名称:pygame_example,代码行数:59,代码来源:loadingscene.py

示例9: create_layer

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
 def create_layer(self):
     bgimg = media.load_image('bg.png').convert()
     rbgimg = bgimg.get_rect()
     rows = int(600 / rbgimg.height) + 2
     
     layer = Surface((rbgimg.width, 600))
     for y in xrange(rows):
         layer.blit(bgimg, rbgimg)
         rbgimg = rbgimg.move([0, rbgimg.height])
     return layer
开发者ID:benoxoft,项目名称:mti880handcopter,代码行数:12,代码来源:ui.py

示例10: create_bottom

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
 def create_bottom(self):
     bgimg = media.load_image('tile_wall.png').convert()
     bgimg = pygame.transform.flip(bgimg, False, True)
     rbgimg = bgimg.get_rect()
     cols = int(1000 / rbgimg.width)
     
     top = Surface((1000, rbgimg.height))
     for x in xrange(cols):
         top.blit(bgimg, rbgimg)
         rbgimg = rbgimg.move([rbgimg.width, 0])
     return top
开发者ID:benoxoft,项目名称:mti880handcopter,代码行数:13,代码来源:ui.py

示例11: create_top

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
 def create_top(self):
     bgimg = media.load_image('tile_wall.png').convert()
     rbgimg = bgimg.get_rect()
     self.top_size = rbgimg.width
     cols = int(1000 / rbgimg.width)
     
     top = Surface((1000, rbgimg.height))
     for x in xrange(cols):
         top.blit(bgimg, rbgimg)
         rbgimg = rbgimg.move([rbgimg.width, 0])
     return top
开发者ID:benoxoft,项目名称:mti880handcopter,代码行数:13,代码来源:ui.py

示例12: add_border

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
 def add_border(self):
     """Draw a border around the thumbnail image Surface."""
     new_surf = Surface((THUMB_SIZE + (BORDER_WIDTH * 2),
                         THUMB_SIZE + (BORDER_WIDTH * 2)))
     new_surf.blit(self.image, (BORDER_WIDTH, BORDER_WIDTH))
     border_rect = Rect(get_line_center(BORDER_WIDTH),
                        get_line_center(BORDER_WIDTH),
                        THUMB_SIZE + BORDER_WIDTH + 1,
                        THUMB_SIZE + BORDER_WIDTH + 1)
     pygame.draw.rect(new_surf, THUMB_BORDER_COLOR, border_rect,
                      BORDER_WIDTH)
     self.image = new_surf
开发者ID:MarquisLP,项目名称:Sidewalk-Champion,代码行数:14,代码来源:stage_select_state.py

示例13: padimage

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
def padimage(self, image): 
    """
    Do a little processing of the input image to make it purdyer.
    Pad the image with transparent pixels so the edges get antialised
    when rotated and scaled.  Looks real nice.
    """

    new = Surface(image.get_rect().inflate(2, 2).size, pygame.SRCALPHA)
    color = image.get_at((0,0))
    color[3] = 0
    new.fill(color)
    new.blit(image, (1,1))
    return new
开发者ID:MacLeek,项目名称:mh,代码行数:15,代码来源:mob.py

示例14: prepare_passage

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
def prepare_passage(text, width, size="normal", colour=(0,0,0)):
    sections = text.split("\n")
    paras = [prepare_paragraph(t,width,size=size,colour=colour)
             for t in sections]
    fullwidth = max(p.get_width() for p in paras)
    fullheight = sum(p.get_height() for p in paras)
    passage = Surface((fullwidth,fullheight),pygame.SRCALPHA)
    passage.fill((255,255,255,0))
    y = 0
    for p in paras:
        passage.blit(p,(0,y))
        y += p.get_height()
    return passage
开发者ID:scavpy,项目名称:Scav-Threads-PyWeek-Sep-2012,代码行数:15,代码来源:typefaces.py

示例15: draw

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import blit [as 别名]
    def draw(self, pressed):
        from pygame.surface import Surface
        from pygame.draw import rect
        from pygame.display import flip

        self.surface.fill(self.surface_color)
        if pressed:
            self.current_position += pressed
            self.current_position %= self.number_buttons
        menu_surface = Surface((self.menu_width, self.menu_height))
        menu_surface.fill(self.surface_color)
        rect(menu_surface, self.selection_color, self.info_list[self.current_position].point_rect)
        for i in range(self.number_buttons):
            menu_surface.blit(self.info_list[i].text_surface, self.info_list[i].text_rect)
        self.surface.blit(menu_surface, self.shift)
        flip()
开发者ID:creators1303,项目名称:Hex_Platform,代码行数:18,代码来源:Graphic.py


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