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


Python sdl2.SDL_Rect方法代码示例

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


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

示例1: __init__

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def __init__(self, texture, x, y, w, h, z=1, destroy=False,
                 texture_name=None):
        self.texture = texture
        if z < 0 or z > 1:
            raise NotImplementedError()
        self.z = z
        self.w = w
        self.h = h
        self.src_rect = sdl2.SDL_Rect(0, 0, w, h)
        self.dest_rect = sdl2.SDL_Rect(x, y, w, h)

        if destroy:
            def destroy_f():
                sdl2.SDL_DestroyTexture(self.texture)

            self.destroy = destroy_f

        if texture_name is not None:
            self.texture_name = texture_name 
开发者ID:kampffrosch94,项目名称:pyAoEM,代码行数:21,代码来源:res.py

示例2: process

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def process(self, world, components):
        # Processing code that will render all existing CParticle
        # components that currently exist in the world. We have a 1:1
        # mapping between the created particle entities and associated
        # particle components; that said, we render all created
        # particles here.

        # We deal with quite a set of items, so we create some shortcuts
        # to save Python the time to look things up.
        #
        # The SDL_Rect is used for the blit operation below and is used
        # as destination position for rendering the particle.
        r = sdl2.SDL_Rect()

        # The SDL2 blit function to use. This will take an image
        # (SDL_Texture) as source and copies it on the target.
        dorender = sdl2.SDL_RenderCopy

        # And some more shortcuts.
        sdlrenderer = self.renderer.sdlrenderer
        images = self.images
        # Before rendering all particles, make sure the old ones are
        # removed from the window by filling it with a black color.
        self.renderer.clear(0x0)

        # Render all particles.
        for particle in components:
            # Set the correct destination position for the particle
            r.x = int(particle.x)
            r.y = int(particle.y)

            # Select the correct image for the particle.
            img = images[particle.type]
            r.w, r.h = img.size
            # Render (or blit) the particle by using the designated image.
            dorender(sdlrenderer, img.texture, None, r)
        self.renderer.present() 
开发者ID:marcusva,项目名称:py-sdl2,代码行数:39,代码来源:particles.py

示例3: render

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def render(self, components):
        global camera, stars

        # Draw stars
        tmp = self.renderer.color
        self.renderer.color = BLACK
        self.renderer.clear()
        self.renderer.color = BLUISH_GRAY
        
        star_coords = [] # stars is a global list of Star objects... for now.
        for s in stars:
            coords = camera.star_to_screen_space(s.direction)
            star_coords.extend(coords)
        self.renderer.draw_point(star_coords)
            
        self.renderer.color = tmp
        # Draw sprites
        r = sdl2.SDL_Rect(0, 0, 0, 0)

        rcopy = sdl2.SDL_RenderCopy
        renderer = self.sdlrenderer
        for sp in components:
            if sp.depth >= 0:
                r.x, r.y, r.w, r.h = -1, -1, 1, 1
            else:
                r.w = int(max(2, (sp.size[0] / (-sp.depth / 15e9))))
                r.h = int(max(2, sp.size[1] / (-sp.depth / 15e9)))
                r.x = sp.x - r.w // 2
                r.y = sp.y - r.h // 2
            if rcopy(renderer, sp.texture, None, r) == -1:
                raise SDLError()
        sdl2.SDL_RenderPresent(self.sdlrenderer) 
开发者ID:vodrilus,项目名称:solar-orbiters,代码行数:34,代码来源:solar_orbiters.py

示例4: __init__

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def __init__(self, **options):
        Component.__init__(self, self, None, **options)
        self.viewport = sdl2.SDL_Rect()
        self._components_activation = OrderedDict()
        self.resources = {}
        self.tints = []
        self.timers = []
        self._running = True
        self.logger.info("Initializing application: %s", self.name)
        sdl2.SDL_Init(self.props.get('init_flags', 0))
        self.register_event_handler(sdl2.SDL_QUIT, self._quit)
        self.register_event_handler(sdl2.SDL_WINDOWEVENT, self._window_event)
        self.keys = sdl2.SDL_GetKeyboardState(None)
        self.window = self._get_window()
        self.renderer = self._get_renderer()
        self.load_resource('font-6', 'font-6.png')
        self.resources['font-6'].make_font(
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?("
            ")[][email protected]:/'., ")
        self.enable()
        try:
            _deep_call(self, 'init')
        except:
            self.quit()
            self._clean_up()
            raise
        sdl2.SDL_ShowWindow(self.window) 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:29,代码来源:app.py

示例5: load

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def load(self):
        self.font = None
        self.font_w = None
        self.font_h = None
        image = self._get_image()
        if not image:
            raise ValueError(
                "can't load resource %r: %s"
                % (self.filename, sdl2.SDL_GetError()))
        try:
            self.texture = \
                sdl2.SDL_CreateTextureFromSurface(self.app.renderer, image)
            self.rect = sdl2.SDL_Rect(0, 0, image.contents.w, image.contents.h)
        finally:
            sdl2.SDL_FreeSurface(image) 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:17,代码来源:resource.py

示例6: draw

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def draw(self, **kwargs):
        if 'rect' in kwargs:
            dest = kwargs['rect']
        elif 'x' in kwargs and 'y' in kwargs:
            dest = sdl2.SDL_Rect(
                kwargs['x'],
                kwargs['y'],
                kwargs.get('w', self.rect.w),
                kwargs.get('h', self.rect.h))
        else:
            dest = self.rect
        sdl2.SDL_RenderCopy(self.app.renderer, self.texture, self.rect, dest) 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:14,代码来源:resource.py

示例7: write

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def write(self, x=0, y=0, text=""):
        assert self.font is not None, "the resource is not a font"
        src = sdl2.SDL_Rect(0, 0, self.font_w, self.font_h)
        dest = sdl2.SDL_Rect(x, y, self.font_w, self.font_h)
        for c in text:
            try:
                src.x = self.font.index(c) * self.font_w
            except ValueError:
                pass
            else:
                sdl2.SDL_RenderCopy(self.app.renderer, self.texture, src, dest)
                dest.x += self.font_w 
开发者ID:cecton,项目名称:pysdl2-sdl2ui,代码行数:14,代码来源:resource.py

示例8: getButtonClicked

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def getButtonClicked(x, y):
	pt = sdl2.SDL_Point(x, y)
	if sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*YELLOWRECT)):
		return YELLOW
	elif sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*BLUERECT)):
		return BLUE
	elif sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*REDRECT)):
		return RED
	elif sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(*GREENRECT)):
		return GREEN
	return None 
开发者ID:rswinkle,项目名称:inventwithpython_pysdl2,代码行数:13,代码来源:simulate_pysdl2.py

示例9: make_text

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def make_text(SPRITE_FACTORY, text, top, left, **kwargs):
	button = SPRITE_FACTORY.from_text(text, **kwargs)
	button.position = top, left
	return (button, sdl2.SDL_Rect(top, left, *button.size)) 
开发者ID:rswinkle,项目名称:inventwithpython_pysdl2,代码行数:6,代码来源:slidepuzzle_pysdl2.py

示例10: getSpotClicked

# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Rect [as 别名]
def getSpotClicked(board, x, y):
	# from the x & y pixel coordinates, get the x & y board coordinates
	pt = sdl2.SDL_Point(x, y)
	for tileX in range(len(board)):
		for tileY in range(len(board[0])):
			left, top = getLeftTopOfTile(tileX, tileY)
			if sdl2.SDL_PointInRect(pt, sdl2.SDL_Rect(left, top, TILESIZE, TILESIZE)):
				return (tileX, tileY)
	return (None, None) 
开发者ID:rswinkle,项目名称:inventwithpython_pysdl2,代码行数:11,代码来源:slidepuzzle_pysdl2.py


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