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


Python Surface.convert_alpha方法代码示例

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


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

示例1: order_reversed_spritesheet

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import convert_alpha [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

示例2: update

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import convert_alpha [as 别名]
    def update(self, duration):
        """ update all the contained linewidgets.
        Return right away if no text has changed.
        """

        if self.dirty == 0:  # no new text has been added
            return

        # make the box
        size = self.rect.size
        bgcolor = self.bgcolor
        if bgcolor:  # completely opaque bg
            img = Surface(size)
            img.fill(self.bgcolor)
            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))  # black
            img = img.convert_alpha()

        # blit each line
        for wid in self.linewidgets:
            wid.update(duration)
            img.blit(wid.image, wid.rect)

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

示例3: __init__

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import convert_alpha [as 别名]
    def __init__(self, evManager, numlines=3, rect=(0, 0, 100, 20), txtcolor=(255, 0, 0), bgcolor=None):
        Widget.__init__(self, evManager)

        self._em.reg_cb(ChatlogUpdatedEvent, self.on_remotechat)
        self._em.reg_cb(MGameAdminEvt, self.on_gameadmin)
        self._em.reg_cb(MNameChangeFailEvt, self.on_namechangefail)
        self._em.reg_cb(MMyNameChangedEvent, self.on_namechangesuccess)
        self._em.reg_cb(MNameChangedEvt, self.on_namechangesuccess)
        self._em.reg_cb(MdHpsChangeEvt, self.on_updatehps)

        self.font = Font(None, config_get_fontsize())
        self.rect = rect
        size = rect.size
        self.txtcolor = txtcolor
        self.bgcolor = bgcolor
        if bgcolor:  # completely opaque bg
            img = Surface(size)
            img.fill(self.bgcolor)
            img = img.convert()
        else:  # more or less transparent
            img = Surface(self.rect.size, SRCALPHA)  # handles transparency
            transparency = 50  # 0 = transparent, 255 = opaque
            img.fill((0, 0, 0, transparency))  # black
            img = img.convert_alpha()
        self.image = img

        self.maxnumlines = numlines
        self.linewidgets = deque(maxlen=numlines)  # deque of TextLabelWidgets
开发者ID:gentimouton,项目名称:crowd-control,代码行数:30,代码来源:widgets.py

示例4: update

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import convert_alpha [as 别名]
    def update(self, duration):
        """ reblit the entries on my rect """
        if self.dirty == 0:
            return

        # make the transparent box
        size = self.rect.size
        img = Surface(size, SRCALPHA)
        transparency = 50 # 0 = transparent, 255 = opaque
        img.fill((0, 0, 0, transparency))
        img = img.convert_alpha() # TODO: alpha or color key?

        # blit each entry
        for entry in self.entries:
            entry.update(duration)
            img.blit(entry.image, entry.rect)

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

示例5: add_underline

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import convert_alpha [as 别名]
    def add_underline(self):
        """Draws an underline on the text Surface, on top the text."""
        # The underline will be drawn from the bottom of the text Surface
        # and will extend its entire horizontal length.
        text_width = self.rect.width
        text_height = self.rect.height

        start_point = (0, text_height - 4)
        end_point = (text_width, text_height - 4)

        # The underline is drawn onto a new Surface with the same dimensions
        # as the text Surface, but slightly taller to account for the
        # underline. The text is drawn on top.
        new_image = Surface((text_width, text_height + 4), pygame.SRCALPHA, 32)
        new_image = new_image.convert_alpha()
        draw.line(new_image, UNDERLINE_COLOUR, start_point,
                  end_point, UNDERLINE_SIZE)
        new_image.blit(self.image, (0, 0))

        self.image = new_image
开发者ID:MarquisLP,项目名称:Sidewalk-Champion,代码行数:22,代码来源:settings_state.py

示例6: SettingsScreen

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import convert_alpha [as 别名]
class SettingsScreen(Screen):
	""" The settings screen class.

	An instance of this class represents a settings screen.

	Attributes:
		_settings: The game settings.
		_entries: The settings entries.
		_screen: The screen to draw on.
		_width: The width of the window.
		_height: The height of the window.
		_window: The surrounding window.
		_bg: The background picture.
		_font: The font to use.
		_font_height: The height of the used font.
		_selected: The index of the selected settings entry.
		_first_y: The y coordinate of the first entry.
		_delta_y: The difference in the y axis between the entries.
		_plus_button: The pre-rendered plus button.
		_minus_button: The pre-rendered minus button.
	"""
	# color of an entry
	SELECTED_COLOR = (255, 255, 0)
	# color of the selected entry
	COLOR = (150, 150, 0)

	def __init__(self, screen, width, height, window, settings):
		""" Generates a new instance of this class.

		Generates a new instance of this class and sets the field information.

		Args:
			screen: The screen to draw on.
			width: The width of the screen.
			height: The height of the screen.
			window: The surrounding window.
			settings: The game settings.
		"""
		self._settings = settings

		self._screen = screen
		self._width = width
		self._height = height
		self._window = window
		self._bg = PictureManager.MANAGER.get_picture("menuBackground.png")
		self._bg = pygame.transform.scale(self._bg, (width, height))
		self._font = pygame.font.SysFont("arial", 24)
		self._font_height = self._font.get_linesize()
		self._selected = 0

		sound_entry = SettingsEntry(Settings.SOUND_VOLUME, "Sound", SettingsEntry.SCALE10,
									self._settings.get_value(Settings.SOUND_VOLUME), button_size=self._font_height)
		music_entry = SettingsEntry(Settings.MUSIC_VOLUME, "Music", SettingsEntry.SCALE10,
									self._settings.get_value(Settings.MUSIC_VOLUME), button_size=self._font_height)
		fx_entry = SettingsEntry(Settings.FX_VOLUME, "Effects", SettingsEntry.SCALE10,
								 self._settings.get_value(Settings.FX_VOLUME), button_size=self._font_height)
		joystick_entry = SettingsEntry(Settings.JOYSTICK, "Controller", SettingsEntry.BOOL,
								 self._settings.get_value(Settings.JOYSTICK), button_size=self._font_height)
		back_entry = SettingsEntry(None, "back", SettingsEntry.ACTION,
								 None, action=self.back)

		self._entries = (sound_entry, music_entry, fx_entry, joystick_entry, back_entry)

		self._first_y = 0.5 * (self._height - len(self._entries) * (self._font_height + 5))
		self._delta_y = self._font_height + 5

		self._plus_button = None
		self._minus_button = None

		self._unchecked_bool = None
		self._checked_bool = None

		self._prepare_buttons()

	def _prepare_buttons(self):
		""" Prepares the buttons.

		This method pre-renders the plus and minus buttons.
		"""
		# draw plus button
		self._plus_button = Surface((self._font_height, self._font_height), pygame.SRCALPHA, 32)
		self._plus_button.convert_alpha()
		pygame.draw.rect(self._plus_button, SettingsScreen.COLOR, Rect(0, self._font_height/3, self._font_height, self._font_height/3))
		pygame.draw.rect(self._plus_button, SettingsScreen.COLOR, Rect(self._font_height/3, 0, self._font_height/3, self._font_height))

		# draw minus button
		self._minus_button = Surface((self._font_height, self._font_height), pygame.SRCALPHA, 32)
		self._minus_button.convert_alpha()
		pygame.draw.rect(self._minus_button, SettingsScreen.COLOR, Rect(0, self._font_height/3, self._font_height, self._font_height/3))

		# draw unchecked bool button
		self._unchecked_bool = Surface((self._font_height, self._font_height), pygame.SRCALPHA, 32)
		self._unchecked_bool.convert_alpha()
		pygame.draw.rect(self._unchecked_bool, SettingsScreen.COLOR, Rect(0, 0, self._font_height, self._font_height), 3)

		# draw checked bool button
		self._checked_bool = Surface((self._font_height, self._font_height), pygame.SRCALPHA, 32)
		self._checked_bool.convert_alpha()
		pygame.draw.rect(self._checked_bool, SettingsScreen.COLOR, Rect(0, 0, self._font_height, self._font_height), 3)
		pygame.draw.line(self._checked_bool, SettingsScreen.COLOR, (0, 0), (self._font_height, self._font_height), 3)
#.........这里部分代码省略.........
开发者ID:donhilion,项目名称:JumpAndRun,代码行数:103,代码来源:settings_screen.py

示例7: Surface

# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import convert_alpha [as 别名]
    pygame.init()
    screen = pygame.display.set_mode((300, 300))

    bg = Surface((200, 200))
    bg.fill((255, 0, 0))    
    bg = bg.convert()
    screen.blit(bg, (50, 50))

    font = Font(None, 25)
    txt = 'qwertyuiop'
    txtimg = font.render(txt, 1, (255, 255, 255)) # antialiasing w/o bg => alpha 
    
    b = Surface((100, 100), SRCALPHA)
    b.fill((111, 111, 111, 128))
    b.blit(txtimg, (10, 10))
    b = b.convert_alpha()
    screen.blit(b, (25, 25))
    
    # what's below has better perf, but bad output when antialias + transparency 
    c = Surface((100, 100))
    colkey = (255, 0, 255)
    c.set_colorkey(colkey, RLEACCEL)
    c.fill(colkey) # make the surface bg invisible
    
    c2 = Surface((100, 100))
    c2.fill((111, 111, 111))
    c2.set_alpha(128, RLEACCEL) # semi-transparent gray bg
    #c.blit(c2, (0, 0))
    c2 = c2.convert()
    txtimg2 = txtimg.convert(c) # sucks if txtimg is antialiased
    c.blit(txtimg2, (10, 10))
开发者ID:gentimouton,项目名称:crowd-control,代码行数:33,代码来源:view.py


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