本文整理汇总了Python中pygame.surface.Surface.set_alpha方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.set_alpha方法的具体用法?Python Surface.set_alpha怎么用?Python Surface.set_alpha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame.surface.Surface
的用法示例。
在下文中一共展示了Surface.set_alpha方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activate
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import set_alpha [as 别名]
def activate(self):
xsize = 300
ysize = 70
bkg = Surface((xsize, ysize))
bkg.lock()
bkg.fill((128,128,128))
for i in range(1, 4):
draw.rect(bkg,(i*32,i*32,i*32),(4-i,4-i,xsize+(i-4)*2,ysize+(i-4)*2),3)
corner = (64,64,64)
bkg.set_at((0,0), corner)
bkg.set_at((xsize,0), corner)
bkg.set_at((xsize,ysize), corner)
bkg.set_at((0,ysize), corner)
bkg.unlock()
bkg.set_alpha(64)
self.bkg = bkg
if self.title != None:
banner = OutlineTextBanner(self.title, (200,200,200), 20)
self.title_image = banner.render()
self.title_image.set_alpha(96)
self.arrow = res.loadImage("wait_arrow.png", colorkey=1)
示例2: __init__
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import set_alpha [as 别名]
def __init__(self, evManager, numlines=3, rect=(0, 0, 100, 20), txtcolor=(255, 0, 0), bgcolor=None):
Widget.__init__(self, evManager)
# When receiving an event containing text,
# add or remove that text to the widget's set of text lines to display.
# addevents_attrs maps event classes to the text attr of events
# that add text to display.
self.addevents_attrs = {MdAddPlayerEvt: "pname", MNameChangedEvt: "newname", MMyNameChangedEvent: "newname"}
for evtClass in self.addevents_attrs:
self._em.reg_cb(evtClass, self.on_addtextevent)
# rmevents_attrs maps event classes to the text attributes of events
# that remove text to display.
self.rmevents_attrs = {MPlayerLeftEvt: "pname", MNameChangedEvt: "oldname", MMyNameChangedEvent: "oldname"}
for evtClass in self.rmevents_attrs:
self._em.reg_cb(evtClass, self.on_rmtextevent)
self.texts = [] # Each text is a player name.
# gfx
self.font = Font(None, config_get_fontsize())
self.rect = rect
self.txtcolor = txtcolor
self.bgcolor = bgcolor
img = Surface(rect.size)
if bgcolor:
img.fill(bgcolor)
else:
img.set_alpha(0, RLEACCEL) # fully transparent
self.image = img
self.maxnumlines = numlines
self.linewidgets = deque(maxlen=numlines) # deque of TextLabelWidgets
示例3: Font
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import set_alpha [as 别名]
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))
c = c.convert()
screen.blit(c2, (125, 25))
screen.blit(c, (125, 25))
pygame.display.update()
while pygame.event.poll().type != KEYDOWN:
pygame.time.delay(10)
示例4: __init__
# 需要导入模块: from pygame.surface import Surface [as 别名]
# 或者: from pygame.surface.Surface import set_alpha [as 别名]
class FieldView:
def __init__(self, game_data):
self.game_data = game_data
self.mouse_x, self.mouse_y = 0, 0
self.sm = SpriteManager()
self.selected_tile_surface_no_building = Surface((32, 32))
self.selected_tile_surface_no_building.fill(0xb7f315)
self.selected_tile_surface_no_building.set_alpha(124)
self.selected_tile_surface_destroy = Surface((32, 32))
self.selected_tile_surface_destroy.fill(0xff0000)
self.selected_tile_surface_destroy.set_alpha(124)
self.selected_tile_surface = self.selected_tile_surface_no_building
self.road_data = (1, 1, 0, 10, 0, 9, 0, 4, 1, 1, 8, 6, 7, 5, 3, 2)
def draw_sprite(self, screen, x, y, sprite):
if x + 32 <= 600:
screen.blit(sprite, [x, y])
elif 632 > x + 32 > 600:
screen.blit(sprite, [x, y], Rect(0, 0, 600 - x, sprite.get_height()))
def draw_field(self, screen):
for x in range(0, 20):
for y in range(0, 20):
# New, better rendering that draws part of map that is currently on screen
mx = x + self.game_data.dx / 32
my = y + self.game_data.dy / 32
sx = x * 32 - self.game_data.dx % 32
sy = y * 32 - self.game_data.dy % 32
self.draw_sprite(screen, sx, sy, self.sm.sprites[self.game_data.game_map[mx][my].ground])
if self.game_data.game_map[mx][my].resource:
self.draw_sprite(screen, sx, sy, self.sm.sprites[self.game_data.game_map[mx][my].resource])
if self.game_data.game_map[mx][my].building == 'center':
self.draw_sprite(screen, sx, sy - 64, self.sm.sprites['center'])
elif self.game_data.game_map[mx][my].building == 'road':
self.draw_road_tile(self.game_data.game_map, mx, my, screen)
elif self.game_data.game_map[mx][my].building:
self.draw_sprite(screen, sx, sy, self.sm.sprites[self.game_data.game_map[mx][my].building])
for expedition in self.game_data.expeditions:
self.draw_sprite(screen, expedition.x * 32 - self.game_data.dx, expedition.y * 32 - 28 - self.game_data.dy, self.sm.sprites['human'])
for monster in self.game_data.monsters:
self.draw_sprite(screen, monster.x * 32 - self.game_data.dx, monster.y * 32 - self.game_data.dy, self.sm.sprites['monster'])
lighted_x = ((self.mouse_x + self.game_data.dx) / 32) * 32 - self.game_data.dx
lighted_y = ((self.mouse_y + self.game_data.dy) / 32) * 32 - self.game_data.dy
self.set_selecter_surface()
#self.draw_sprite(screen, lighted_x, lighted_y, self.selected_tile_surface)
screen.blit(self.selected_tile_surface, [lighted_x, lighted_y], Rect(0, 0, 32, self.selected_tile_surface.get_height()))
def draw_road_tile(self, game_map, position_x, position_y, screen):
"""
Road drawing as it have to be
"""
tile_num = 0
if game_map[position_x][position_y - 1].building == 'road':
tile_num += 1
if game_map[position_x - 1][position_y].building == 'road':
tile_num += 2
if game_map[position_x + 1][position_y].building == 'road':
tile_num += 4
if game_map[position_x][position_y + 1].building == 'road':
tile_num += 8
sx = position_x * 32 - self.game_data.dx
sy = position_y * 32 - self.game_data.dy
self.blit_road_tile(sx, sy, screen, self.road_data[tile_num])
#TODO: merge two blitting methods
def blit_road_tile(self, x, y, screen, item):
sprite = self.sm.sprites['road']
if x + 32 <= 600:
screen.blit(sprite, [x, y], Rect(item * 32, 0, 32, sprite.get_height()))
elif 632 > x + 32 > 600:
screen.blit(sprite, [x, y], Rect(item * 32, 0, 600 - x, sprite.get_height()))
def set_selecter_surface(self):
if self.game_data.uis.building and self.game_data.uis.building != 'destruct':
surface = SpriteManager().sprites[self.game_data.uis.building].copy()
self.selected_tile_surface = surface
elif self.game_data.uis.building == 'destruct':
self.selected_tile_surface = self.selected_tile_surface_destroy
else:
self.selected_tile_surface = self.selected_tile_surface_no_building