/!\ Latest version here is 0.2.01. This file is outdated. Latest version is still not documented yet.
Even if the layered sprite function is currently being developped by monogatari's creator, we needed another feature for our game that was the perfect crossfade. In HTML, it is possible to stack multiple images in a background, but crossfading (or in other words, applying the "merge" blend mode) is still in the CSS4 drafts. Even worse, applying a transition to the background-image proprety is not in the standarts...
But the strange and cool thing is that it's available in most WebKit based browsers (at least chrome 17+), and that transition applies exactly the "merge" blend mode for the old and the new background. To summary, this is another way to add the layered sprites feature, with their pros and cons, and allow in addition some browsers to have a perfect transition when sprites needs to be changed.
- 👍 Some browsers will apply a perfect crossfade transition.
- 👎 Currently, Layers should have the same size, or at least the same width
- 👎 This is unstable, because it edits directly the image generated by the VN lib. If the lib haves to edit the original sprites, it might fails !
- 👎 This technique is not standart. Transitions will not work with firefox.
- 👎 Playing with background images is not a good way to display images...
- Currently, the code will work fine only for webkit-based browsers.
Thus, Firefox can't apply fading transitions (that will be ugly, so sad, it's my everyday browser, but the sacrifice worth)... - This custom action is still in beta stage. I might update the syntax ! This is not well documented ! You must master the Monogatari Lib if you wish to use this addon.
$ _layered [characterName] [reference1] [reference2] [...referenceX] ([with] [...classes])
[characterName]
: must have been defined both in GLOBALS.layered[] and monogatari.characters({}).[referenceX]
: You should add these arguments as many as total amount of layers defined. Possible values are "empty" (No need to explain), a reference of layer defined inGLOBALS.layered[<characterName>]
, or "-" to keep the last value defined.- with
[...classes]
: sames as used in the show character command.
And voilà !! Usage is the same as the show character
command, but you replace it
with $ _layered
and add a reference for each layers, and you need of course
to include it by copy-pasting in the main.js (I don't recommand it) or
including with the script tag.
-
Extract and copy the files inside
PNG_layers_for_testing.zip
to the folderassets/characters/layered
, to get some PNG layers for testing. Example code in this section will works with thoses files. -
Copy the included
main.js
file tojs/addons/$_layered/main.js
(feel free to change the name or not, as long as it works in your project) -
Include the script :
<script src="js/addons/$_layered/main.js"></script>
-
Define the testing character in
monogatari.characters ({});
'test' : { name: 'test', color: '#aaaaaa', directory: 'layered', sprites: { default: "2-body.png", } }
-
Defines the layers of the character (paste this directly at the end of the script
js/addons/$_layered/main.js
)// parameters are defined inside a global object if (typeof GLOBALS !== "object" || typeof GLOBALS.layered !== "object") { var GLOBALS = { layered: {} } } // Define characters layers like this : (might change if I plan to upgrade my function!) // GLOBALS.layered.<your character name> = [...] GLOBALS.layered.test = [ { // Fallback + storage layersHistory: [], default: 'default'//must be an identifier defined with monogatari.characters // Because if it fails, _layered will run "show character <characterName> <default>" }, { // layer 1 (front) handsDown: "assets/characters/layered/1-handsDown.png", handsUp: "assets/characters/layered/1-handsUp.png", }, { // layer 2 (middle) body: "assets/characters/layered/2-body.png" }, { // layer 3 (back) headNope: "assets/characters/layered/3-headNope.png", headYes: "assets/characters/layered/3-headYes.png" } // add others layers if needed ! but requires to add "n" more arguments for "n" numbers of layers ]
-
Demo script :
script["layered_demo"] = [ "show scene white", "$ _layered test handsDown body headNope with fadeIn end-fadeOut", "test I'm upset", "$ _layered test handsUp - headYes with fadeIn end-fadeOut", "test Now, I'm <em>not</em> upset", "$ _layered test handsDown - empty with fadeIn end-fadeOut", "test WTF I don't have any heads ?!", "test that's it !", "end" ];
-
Then jump to the label
layered_demo
!