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


Python Rect.clip方法代码示例

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


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

示例1: test_clip

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import clip [as 别名]
 def test_clip(self):
     r1 = Rect(1, 2, 3, 4)
     self.assertEqual(Rect(1, 2, 2, 2), r1.clip(Rect(0, 0, 3, 4)))
     self.assertEqual(Rect(2, 2, 2, 4), r1.clip(Rect(2, 2, 10, 20)))
     self.assertEqual(Rect(2, 3, 1, 2), r1.clip(Rect(2, 3, 1, 2)))
     self.assertEqual((0, 0), r1.clip(20, 30, 5, 6).size)
     self.assertEqual(r1, r1.clip(Rect(r1)), "r1 does not clip an identical rect to itself")
开发者ID:G2ProjectUAV,项目名称:Project-UAV,代码行数:9,代码来源:rect_test.py

示例2: _update

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import clip [as 别名]
 def _update (self, col, row, tile_type_id, tile_rect=None):
     if self._cache_graphic:
         if tile_type_id in self._cache:
             g = self._cache[tile_type_id]
         else:
             g = self._type_to_graphic(tile_type_id)
             self._cache[tile_type_id] = g
     else:
         g = self._type_to_graphic(tile_type_id)
     dest = self._orig_sfc
     if tile_rect is None:
         tile_rect = self.grid.tile_rect(col, row)
     if isinstance(g, (Graphic, pg.Surface, basestring)):
         g = (g,)
     if (g is not None and
         isinstance(g[0], (Graphic, pg.Surface, basestring))):
         sfc = g[0]
         if isinstance(sfc, basestring):
             sfc = self._load_img(sfc)
         elif isinstance(sfc, Graphic):
             sfc = sfc.surface
         if len(g) == 1:
             alignment = rect = None
         else:
             if isinstance(g[1], int) or len(g[1]) == 2:
                 alignment = g[1]
                 rect = None
             else:
                 alignment = None
                 rect = g[1]
             if len(g) == 3:
                 if rect is None:
                     rect = g[2]
                 else:
                     alignment = g[2]
         if alignment is None:
             alignment = 0
         if rect is None:
             rect = sfc.get_rect()
         # clip rect to fit in tile_rect
         dest_rect = Rect(rect)
         dest_rect.center = tile_rect.center
         fit = dest_rect.clip(tile_rect)
         rect = Rect(rect)
         rect.move_ip(fit.x - dest_rect.x, fit.y - dest_rect.y)
         rect.size = dest_rect.size
         # copy rect to tile_rect with alignment
         pos = gameutil.align_rect(rect, tile_rect, alignment)
         dest.blit(sfc, pos, rect)
     else:
         if g is None:
             g = (0, 0, 0, 0)
         # now we have a colour
         dest.fill(gameutil.normalise_colour(g), tile_rect)
     return tile_rect
开发者ID:ikn,项目名称:wearhouse,代码行数:57,代码来源:graphics.py

示例3: future

# 需要导入模块: from pygame import Rect [as 别名]
# 或者: from pygame.Rect import clip [as 别名]

#.........这里部分代码省略.........
            self.background = osd.get_singleton().getsurface(rect=self.rect)
            self.updates = []

        elif len(self.updates) > 0:

            # find the topleft corner
            x = self.rect.right
            y = self.rect.bottom
            for i in self.updates:
                x = min(x, i.left)
                y = min(y, i.top)

            # find the total rect of the collisions
            upd = Rect(x, y, 0, 0)
            upd.unionall_ip(self.updates)
            self.updates = []

            x      = upd[0] - self.rect.left
            y      = upd[1] - self.rect.top
            bg_tmp = osd.get_singleton().getsurface(rect=upd)

            self.background.blit(bg_tmp, (x, y))

        self.surface.blit(self.background, (0,0))


    def get_rect(self):
        """ Get the rectangle of the current object
        @returns: the rectangle tuple
        """
        logger.log( 9, 'get_rect()')
        return self.rect


    def start(self):
        """ Starts the animation """
        logger.log( 9, 'start()')
        render.get_singleton().add_animation(self)
        if not self.bg_wait:
            self.active = True


    def stop(self):
        """ Stops the animation from being polled """
        logger.log( 9, 'stop()')
        self.active = False


    def remove(self):
        """ Flags the animation to be removed from the animation list """
        logger.log( 9, 'remove()')
        self.active = False

        # set the org. bg if we use this
        if self.bg_update:
            osd.get_singleton().putsurface(self.background, self.rect.left, self.rect.top)
            osd.get_singleton().update([self.rect])

        self.delete = True


    def damage(self, rectstyles=[]):
        """ Checks if the screen background has been damaged

        @note: If the rect passed damages our rect, but no actual blit is done
        on osd.screen, we'll end up with a copy of our animation in our bg. This is BAD.
        """
        logger.log( 9, 'damage(rectstyles=%r)', rectstyles)
        if not (self.bg_redraw or self.bg_update) or rectstyles == None:
            return

        for rect in rectstyles:
            if rect == None:
                continue

            if self.rect.colliderect(rect):
                if self.bg_wait:
                    self.active = True

                self.updates.append(self.rect.clip(rect))
                logger.debug('Damaged, updating background')


    def poll(self, current_time):
        """ Poll the animations """
        logger.log( 9, 'poll(current_time=%r)', current_time)
        if self.next_update < current_time:
            self.next_update = current_time + self.interval

            if self.bg_update:
                self.set_screen_background()

            self.draw()
            return self.rect, self.surface


    def draw(self):
        """ Overload to do stuff with the surface """
        logger.log( 9, 'draw()')
        pass
开发者ID:adozenlines,项目名称:freevo1,代码行数:104,代码来源:base.py


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