當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。