Renpy Portrait System v1.X
A while ago I was confronted with a problem. I wanted to be able to use blink/lip-flap for my portraits in Renpy, but quickly discovered this would lead to excessive amounts of code. I posted that there topic after struggling with the issue myself, and eventually got a reply. It's from there I worked slowly on getting the code to work for me.
Given I'm sure there are others that want this sort of thing, I worked on making the code Bryan Tsang provided into something that would work for others as well. Thus, a demo to show off this system.
- By specifying even just a single line, you can define a character portrait that will animate as required, instead of copying 20+ lines for every pose/image.
- Includes a text-beep effect that can vary between characters.
- Enables "introductory" animations and similar - short sequences that play when a character enters a pose.
- Stores portrait, eyes, and mouth, all in one file per pose.
The minimal, basic portrait code looks like this:
image june idle = Portrait("june/idle.png", eyepos=(144, 192), moupos=(144,256), speaker="june")
The code works pretty straight forward - you have the file, the position of the eyes and mouth elements on the larger portrait, and the callback. The callback is something specified in Character() code, so that the message sound and lip-flap plays when it's expected to. The demo below also has a custom system for Character definitions, but this isn't necessary.
The width is 416px by default, and the 128x64 slices are placed next to the portrait. The width can be changed by specifying it in the above line of code, so long as it correctly matches the file's portrait width.
A portrait is set up as a single image like so:
After that, you can just use the show command just like other images: show june idle.
An additional thing to note is that the portraits are by default 640px tall to allow bleeding. By exceeding the game window, the portrait will not show its edges with regards to shake effects. (So long as it's vertically centred.) You will, however, need to edit the code yourself if you want taller/shorter portraits or to change the blink/lip-flap sprites.
Download and Credits
Download Demo (v1.3)
This demo expands on some other ways to use the script than what is mentioned here.
Credit would be appreciated, given to myself - Taylor, and to Bryan Tsang/@bvtsang.
I mentioned above how you would need to alter the core code to support a different height for character portraits, as well as differently formatted eye/mouth sprites.
Height: Within the portrait code there exists references to 640. This is the height of the graphics in the demo. Modifying this will allow you to work with different sized graphics. I personally wouldn't recommend making each character different heights, as this would make it harder to keep them correctly scaled when standing between one another.
Eyes and Mouth: In the init of the Portrait class there are two "secret" variables - eyesize and mousize. By altering the numbers (and the images), you should be able to get the eyes and mouth sprites to be the sizes you desire. These can also be used in image definitions to specify unique dimensions for that portrait.
You may also wish to check the Set frames lines of redraw_eyes and redraw_mouth, as they specify where the engine crops the animation parts from, should you want to move the eye and mouth origins on your templates. The mouth segments are spaced 32px apart from the eye part, as can be seen with the line mouth_y_orign = self.eyes*2 + 32.
Changelog(v1.3) Friday, 27 January 02017
(v1.2) Wednesday, 23 December 02015
Compatibility fix for Renpy 126.96.36.199.
(v1.1) Friday, 4 December 02015
Replaced flatten code with actual Flatten() function.
Note: As of writing this system may only transform (character fade) correctly in Renpy 6.99.6 and 188.8.131.525+. This is probably not a fault of my code, but, I dunno. Namely, .99.7 Release causes graphical issues.
(v1.0a) Thursday, 17 September 02015
Fixed a bug with portrait flattening, which caused portraits to not be displayed correctly when changing window size or going full-screen.
(v1.0) Tuesday, 4 February 02015
Minor change to Character Template to fix a bug in Renpy 184.108.40.2069 to do with readback/text history.
Minor grammar fixes in the demo.