Map Transitions

Hi!


I'm new to RPG Maker MV. I have a background in JavaScript, HTML, and SVG. Not so much with the HTML5 Canvas or Pixijs. I was hoping someone could point me in the right direction in terms of API documentation or examples. I'd like to create a custom map transition. It involves controlling the fade out (fade to about 75% black, not 100%), and creating some shapes to move around. These shapes would eventually block the player's view. When the map is loaded, the shapes would move out of the way and then be removed.


These shapes could be created and held off screen as they technically would only need to be redrawn if the resolution were to change. They would need to be drawn against the rendered resolution, not the actual resolution. Would it be a waste to drawn them for every transition? I'm sure there is a more standard term for it, I just don't know it. Consider the following situation. You have a shiny HD monitor (1920x1080). But your freshly installed game is running at 1280x768 until you change your video settings. The shapes would need to be drawn against the 1280x768 resolution to be consistent with the rest of the game.


Not all of the shapes would be moved individually, instead they would be a part of a group, and it is that group as a whole that would be moved. Why update the position of dozens of things, when you can just update the position of a few and get the same result? Rendering wise I don't imagine it would be much different, I'm thinking more of how much work the script has to do. Less work is more performance, right?


Cut scenes or events may use something else to suite the mood, but this would be used on most/all normal map to map transitions.


I have most of the script done. The math is all there. I have a proof of concept that works as desired with just HTML, I just need to draw/animate it in a way that works for the canvas / RPGM MV. I don't imagine looking up canvas methods on MDN (https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API ) will be what I need to know to get this to work.


Is the documentation available on GitHub (so we can point to specific versions of it on the forums so that conversations don't lose context?) or is it just available through the help menu in the software?


Thanks!
I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.


MV Deployment is for when your game is finished and you have problems deploying it to mobile, web or whatever
Apologies. I was a bit too eager to get started and misread deployment as development. Thank you Andar. 
**status update** I'm still digging for more information, but I think I've found a couple leads.


For "event handling", it looks like either Game_Screen or one of the Scene_* objects will have what I'm looking for. I'm still not sure whether or not I need to worry about Scene_Manager.


Game_Screen.prototype.startFadeOut
Game_Screen.prototype.startFadeIn
Scene_Base.prototype.startFadeIn
Scene_Base.prototype.startFadeOut




For the rendered dimensions I'm looking for it looks like it will be a method on the Graphics object.

  1. height() and width() 
  2. boxWidth() and boxHeight()

Going off of my prior example, I'm guessing [1] will give me 1280x768 and [2] would give me 1920x1080, is that correct?
I've been playing around with Scene_Base and Scene_Map. I've done a few things right! and a few things very wrong. At the very least I think I get how the current math works. It was big enough that I thought it warranted its own post:






I somewhat understand how the fade is being set.


// rpg_core.js
/**
* The opacity of the sprite (0 to 255).
*
* @property opacity
* @type Number
*/
Object.defineProperty(ScreenSprite.prototype, 'opacity', {
get: function () {
return this.alpha * 255;
},
set: function (value) {
this.alpha = value.clamp(0, 255) / 255;
},
configurable: true
});


Why not just work directly with a value between 0 and 1? There must be a reason for it, but I don't know it. I can still work with it!


Creating a Transition Manager might be a bit too far above where I'm at now. I'll stick with overwriting startFadeIn, startFadeOut, and updateFade.


I've succeeded in getting the transition to only partially fade out, and then fade in starting from that same point. Next up is to draw the shapes and group them up. Think about how you can group <span> elements inside a <div> in HTML or various shape elements in a <g> element in SVG. By moving that DIV or G, everything contained inside it moves.


My next task is to draw a couple simple shapes and group them. I'm going to continue to div through the source code and the Help Docs, but if someone could point me in the right direction, it would be much appreciated!
So! It has been a few months since I've been able to touch this. What can I say? Work has kept me busy! Very... very... busy.


I'm not sure if anyone is following this yet. It is very young and incomplete, but progress is progress! and progress should be documented.


The good news is I have found all the information I need to draw and how I should go about doing it in a way that works with RPGMaker (vs. just slapping stuff anywhere in the DOM/Canvas just to make it work!). The relationship between Scene_Base and ScreenSprite tipped me off. Also, I have a somewhat better understanding of PIXI containers and the PIXI Graphics class, (not to be confused with RPGMaker's own Graphics class!), that should take care of drawing and grouping once I get to it. It will have to wait as I've decided to tackle making a Transition Manager first.


I've got a pretty good idea how to do it in a non-destructive manner, but it will take some time before I have a proof of concept for it. What is going to be crucial to this is understanding the order of events and methods. As for inheritance, this is what I have so far:

Code:
-   `Scene_Map` extends `Scene_Base`
-   `Scene_Base` extends `Stage`, provided by [RPGMaker MV v1.3.1](http://forums.rpgmakerweb.com/index.php?/topic/66712-rpg-maker-mv-v131-fixes/)
-   `Stage` extends `PIXI.Container.prototype`, provided by [`pixi.js v4.0.0`](https://github.com/pixijs/pixi.js/releases/tag/v4.0.0)
-   `PIXI.Container.prototype` extends `PIXI.DisplayObject.prototype`
-   `PIXI.DisplayObject.prototype` extends `EventEmitter`, provided by [`eventemitter3 v1.2.0`](https://github.com/primus/eventemitter3/tree/1.2.0)



(( One of these days I will get around to asking for markdown syntax highlighting to be added to these forums -.-😉)


The entire application is kicked off by the SceneManager.


//=============================================================================
// main.js
//=============================================================================

PluginManager.setup($plugins);

window.onload = function() {
SceneManager.run(Scene_Boot);
};




I'll be able to figure things out by following the trail, but it will be monotonous as heck! If anyone happens to know the order of operations for Scene_* classes, it would be a big help if you could let me know! For now it looks like I'll be starting with SceneManager.run and SceneManager.goto. Understanding the scene life-cycle will make or break this manager.
Success! Kind of...


I have the basic proof of concept working with just initialize, startFadeIn, startFadeOut, and updateFade. Luckily, I haven't needed to dig into PIXI or eventemitter3 at this point.


I have a number of other methods and properties that need accounting for. Hopefully this doesn't get messy.

Spoiler
Code:
# Yes

`Scene_Base.prototype.fadeSpeed` - update to point to the transition object.
`Scene_Base.prototype.slowFadeSpeed` - if `Scene_Base.prototype.fadeSpeed` is moved to the transition object, this will need to be updated to look for it there.

## Next version

`Scene_Map.prototype.startEncounterEffect` - because the default behavior of hiding characters (at least immediately) may not always be desired. it also references `this.encounterEffectSpeed()`
`Scene_Map.prototype.updateEncounterEffect` - It is responsible for transitions to battles. It also references `this.fadeSpeed()` and `this.encounterEffectSpeed()`.
`Scene_Map.prototype.encounterEffectSpeed` - update to point to encounterEffect object (also to be managed by transition manager.)

# Maybe

`Scene_Title.prototype.start`            - because it references `this.fadeSpeed()`
`Scene_Map.prototype.start`              - because it references `this.fadeSpeed()`
`Scene_Map.prototype.fadeInForTransfer`  - because it references `this.fadeSpeed()`
`Scene_Map.prototype.fadeOutForTransfer` - because it references `this.fadeSpeed()`
`Scene_Battle.prototype.start`           - because it references `this.fadeSpeed()`
`Scene_Battle.prototype.stop`            - because it references `this.fadeSpeed()`

If `Scene_Base.prototype.fadeSpeed` is handled carefully, the above items won't need to be touched.

`Scene_Map.prototype.snapForBattleBackground` - Requires more research.
`Scene_Map.prototype.startFlashForEncounter`  - Requires more research.

# No

`Scene_Base.prototype.isBusy` - `this._fadeDuration` isn't being moved (for compatibility with original transitions), the criteria for this method won't change.
`Scene_Base.prototype.createFadeSprite` - leave in place for compatibility with original transitions. New transitions should not use this / should keep track of transition related properties on the transition, not the scene.
`Scene_Map.prototype.isBusy` - `this._encounterEffectDuration` isn't being moved (for compatibility with original encounterEffects), the criteria for this method won't change.

## TODO

Research hooks to allow for the transition to clean up after itself? (`terminate`, `stop`, ???)



Once accounted for it should be good enough for me to post in a pre-alpha state.



Anyone have a shovel? I have some more digging to do.
Success! Kind of! again...


I don't have any hooks in place for scene class termination yet, but fadeSpeed and slowFadeSpeed have been moved to the transition object.


startEncounterEffect, updateEncounterEffect, and encounterEffectSpeed have all been moved to a new encounter-effect object.


Through the use of plugin parameters, a default encounter effect name can be set. If for some reason that effect doesn't exist, it will fall back to the original effect RPG Maker's own code. The same can be done for every scene class, the the expected use case is primarily around Scene_Map.


At this point you might ask yourself "what is the big deal?" Well, not much, yet. I haven't done anything other developers couldn't do simply by replacing prototypes on Scene_Map with much less complicated code.


The plan is to allow for transitions to change based on Map Notes (maybe?), plugin commands in events, or game variables.


For example, you want one effect for enemy encounters, but maybe you want something more dramatic for bosses or something special for a story driven encounter. Transferring maps? Maybe you have something custom for normal use, but for cut scenes or events, maybe you want something more or less flashy. Maybe you want to use on effect for fade in and a completely different one for fade out. All this is what I am hoping to achieve with this transition manager.


This manager will have a common interface that transition of effect developers can look for and optionally use if they want.


Next up: plugin commands, game variables, map notes, and event notes.

Original thread: https://forums.rpgmakerweb.com/threads/map-transitions.67883/