Here's what I have so far.
Code: Select all
init python:
import math
#Custom Displayable class to handle the text being manipulated. Effectively just a wrapper for text.
class BounceText(renpy.Displayable):
def __init__(self, child, id, bounce_height=10, **kwargs):
# Pass additional properties on to the renpy.Displayable
# constructor.
super(BounceText, self).__init__(**kwargs)
# The child.
self.child = renpy.displayable(child)
self.bounce_height = bounce_height
self.id = id #Should probably rename to word_offset or something.
def render(self, width, height, st, at):
curr_height = math.sin(st+float(self.id))+1 #* float(self.bounce_height) #Adjust this function to get different results.
# Create a transform
t = Transform(child=self.child, zoom = curr_height) #### Altering this changes the effect. ####
#### Replace zoom with yoffset or alpha to try different results ####
# Create a render from the child.
child_render = renpy.render(t, width, height, st, at)
# Get the size of the child.
self.width, self.height = child_render.get_size()
# Create the render we will return.
render = renpy.Render(self.width, self.height)
# Blit (draw) the child's render to our render.
render.blit(child_render, (0, 0))
renpy.redraw(self, 0)
# Return the render.
return render
def visit(self):
return [ self.child ]
#Custom Text Tag that swaps the text for the BounceText class.
#TODO: Make it more compatible with other text tags.
def bounce_tag(tag, argument, contents):
new_list = [ ]
for kind,text in contents:
if kind == renpy.TEXT_TEXT:
disp_id = 0 # Used more to give the characters some offsets in the sine function.
###The commented lines below were an attempt to wrap the BounceText displayables in another container.
###Did not work as I'd hoped but play around with it if you'd like.
#text_list = []
for char in text:
char_text = Text(char)
char_disp = BounceText(char_text, disp_id, argument)
#text_list.append((50*disp_id,50)) #TODO: 50 is placeholder. Should be more programatic
#text_list.append(char_text)
new_list.append((renpy.TEXT_DISPLAYABLE, char_disp))
disp_id = disp_id + 1
#new_composite = Composite((50*(disp_id+1),100), *text_list)
#new_list.append((renpy.TEXT_DISPLAYABLE, new_composite))
disp_id = 0
else:
new_list.append((kind,text))
return new_list
config.custom_text_tags["bt"] = bounce_tag #Adds the text tag.
#end python
define e = Character("Eileen")
label start:
scene bg room
e "I want to test text"
e "Here is some {bt=10}wavy{/bt} text"
e "how did it go?"
Code: Select all
text what id "what" at text_bounce
Poked around the cookbook and didn't find anything similar but let me know if someone else has solved this problem before. Again, I'd like it to be more of a per text character effect rather than per word or whole lines. It feels so close to working but something holding it back.
Known (additional) problems: This pretty much causes all the characters within the text tag to display at once regardless of text speed
Probably won't work with other text tag styling very well
Effect is not reproduced on the History screen.