RainbowSprite, shadowed text
This commit is contained in:
parent
6388584c22
commit
7d46bf3719
|
@ -10,6 +10,7 @@ from pygame.locals import *
|
||||||
|
|
||||||
from Animation import Animation
|
from Animation import Animation
|
||||||
from Vector import Vector
|
from Vector import Vector
|
||||||
|
from extension import get_hue_shifted_surface
|
||||||
|
|
||||||
class Sprite(Animation):
|
class Sprite(Animation):
|
||||||
|
|
||||||
|
@ -444,3 +445,11 @@ class BlinkingSprite(Sprite):
|
||||||
|
|
||||||
def blink(self):
|
def blink(self):
|
||||||
self.toggle_hidden()
|
self.toggle_hidden()
|
||||||
|
|
||||||
|
|
||||||
|
class RainbowSprite(Sprite):
|
||||||
|
|
||||||
|
def __init__(self, parent, image, hue_shift=8, framerate=None):
|
||||||
|
Sprite.__init__(self, parent, framerate)
|
||||||
|
for hue in xrange(0, 360, hue_shift):
|
||||||
|
self.add_frame(get_hue_shifted_surface(image, hue))
|
||||||
|
|
|
@ -161,3 +161,19 @@ def fill_tile(surface, tile):
|
||||||
for x in xrange(0, surface.get_width(), tile.get_width()):
|
for x in xrange(0, surface.get_width(), tile.get_width()):
|
||||||
for y in xrange(0, surface.get_height(), tile.get_height()):
|
for y in xrange(0, surface.get_height(), tile.get_height()):
|
||||||
surface.blit(tile, (x, y))
|
surface.blit(tile, (x, y))
|
||||||
|
|
||||||
|
def get_shadowed_text(text, font, offset, color, antialias=True, shadow_color=(0, 0, 0),
|
||||||
|
colorkey=(255, 0, 255)):
|
||||||
|
foreground = font.render(text, antialias, color)
|
||||||
|
background = font.render(text, antialias, shadow_color)
|
||||||
|
alpha = SRCALPHA if antialias else 0
|
||||||
|
surface = Surface((foreground.get_width() + offset[0],
|
||||||
|
foreground.get_height() + offset[1]), alpha)
|
||||||
|
if not antialias:
|
||||||
|
surface.set_colorkey(colorkey)
|
||||||
|
surface.fill(colorkey)
|
||||||
|
surface.blit(background, ((abs(offset[0]) + offset[0]) / 2,
|
||||||
|
(abs(offset[1]) + offset[1]) / 2))
|
||||||
|
surface.blit(foreground, ((abs(offset[0]) - offset[0]) / 2,
|
||||||
|
(abs(offset[1]) - offset[1]) / 2))
|
||||||
|
return surface
|
||||||
|
|
Loading…
Reference in New Issue