Guest User

Untitled

a guest
Feb 5th, 2017
1,429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * @plugindesc v1.02 Allows you to play a video on the title screen. - Updated for MV 1.3.4
  3.  * <Iavra Video Title>
  4.  * @author Iavra (Update/Fix by Cr1t1cal)
  5.  *
  6.  * @param Video
  7.  * @desc Name of the video to be used.
  8.  * @default
  9.  * @require 1
  10.  * @dir movies/
  11.  * @type file
  12.  *
  13.  * @help
  14.  * Specify the name of the video file in the plugin parameter "Video". The video has to be placed in the
  15.  * "movies" folder of the game and needs to exist as both ".mp4" and ".webm" files, because one of these
  16.  * will be picked, depending on the environment.
  17.  *
  18.  * The video will be played behind the title picture, so either pick "None" as the background image or
  19.  * create a transparent picture to use. You can even use a semi-transparent picture, so the video will be
  20.  * visible behind it.
  21.  *
  22.  * The video will automatically be resized to fit the with and height of the window, while retaining the
  23.  * correct scale and will be centered, if it doesn't fit exactly.
  24.  */
  25. (function($) {
  26.     function Setup() {
  27.         'use strict';
  28.         function VideoFix() {
  29.             this.initialize.apply(this, arguments);
  30.         }
  31.  
  32.         VideoFix.initialize = function() {
  33.             this.setup();
  34.         };
  35.  
  36.         VideoFix.setup = function() {
  37.             this.update();
  38.         };
  39.  
  40.         VideoFix.update = function() {
  41.             this.requestUpdate();
  42.         };
  43.  
  44.         VideoFix.requestUpdate = function() {
  45.             requestAnimationFrame(this.update.bind(this));
  46.         };
  47.  
  48.         VideoFix.initialize();
  49.  
  50.     } Setup();
  51. })(this.IAVRA || (this.IAVRA = {}));
  52.  
  53.  
  54. (function($, undefined) {
  55.     "use strict";
  56.  
  57.     /**
  58.      * Basic helper function to extend objects. Mainly used for inheritance and other prototype-related operations.
  59.      */
  60.     $._extend || ($._extend = function(b, e) { for(var k in e) { b[k] = e[k]; } return b; });
  61.  
  62.     /**
  63.      * Load plugin parameters.
  64.      */
  65.     var _params = $plugins.filter(function(p) { return p.description.contains('<Iavra Video Title>'); })[0].parameters;
  66.     var _param_video = _params['Video'];
  67.  
  68.     /**
  69.      * Holds the HTML video element used to start/pause/rewind the loaded video.
  70.      */
  71.     var _video;
  72.  
  73.     /**
  74.      * Holds the actual sprite, that gets added to Scene_Title.
  75.      */
  76.     var _videoSprite;
  77.  
  78.     /**
  79.      * Gets set to true, once the video has been loaded and causes Scene_Title to wait, beforehand.
  80.      */
  81.     var _ready;
  82.  
  83.     /**
  84.      * Create the video element, set it to auto-loop and creates the Sprite holding it. We also register a
  85.      * callback to be executed, once the video has finished loading, so we can resize and center the sprite.
  86.      */
  87.     var _loadVideo = function() {
  88.         if(!!_videoSprite) { return; }
  89.         _video = document.createElement('video');
  90.         _video.src = _getFilePath();
  91.         _video.loop = 'loop';
  92.         _videoSprite = new PIXI.Sprite(PIXI.Texture.fromVideo(_video));
  93.         _video.onloadeddata = _onLoad;
  94.     };
  95.  
  96.     /**
  97.      * Gets called, once the video has finished loading and scales the sprite. It also gets centered.
  98.      */
  99.     var _onLoad = function() {
  100.         _ready = true;
  101.         var scale = Math.min(Graphics._width / _video.videoWidth, Graphics._height / _video.videoHeight);
  102.         _videoSprite.width = _video.videoWidth * scale;
  103.         _videoSprite.height = _video.videoHeight * scale;
  104.         _videoSprite.x = (Graphics.width - _videoSprite.width) / 2;
  105.         _videoSprite.y = (Graphics.height - _videoSprite.height) / 2;
  106.     };
  107.  
  108.     // var _videoFileExt = Game_Interpreter.prototype.videoFileExt
  109.     // Game_Interpreter.prototype.videoFileExt = function() {
  110.     //     _videoFileExt.call(this)
  111.     //     if (Graphics.canPlayVideoType('video/webm') && !Utils.isMobileDevice()) {
  112.     //         return '.mp4';
  113.     //     } else {
  114.     //         return '.webm';
  115.     //     }
  116.     // };
  117.     /**
  118.      * Returns the path to the video file, depending on the current environment.
  119.      */
  120.     var _getFilePath = function() {
  121.         return 'movies/' + _param_video + Game_Interpreter.prototype.videoFileExt();
  122.     };
  123.  
  124.     //=============================================================================
  125.     // Scene_Title
  126.     //=============================================================================
  127.  
  128.     var _sceneTitle_create = Scene_Title.prototype.create;
  129.     var _sceneTitle_isReady = Scene_Title.prototype.isReady;
  130.     var _sceneTitle_start = Scene_Title.prototype.start;
  131.     var _sceneTitle_stop = Scene_Title.prototype.stop;
  132.     var _sceneTitle_createBackground = Scene_Title.prototype.createBackground;
  133.  
  134.     $._extend(Scene_Title.prototype, {
  135.  
  136.         /**
  137.          * On create, also create our video element. We must do this here, because otherwise we wouldn't
  138.          * be able to determine our current environment, which defines the file extension we have to load.
  139.          */
  140.         create: function() {
  141.             _loadVideo();
  142.             _sceneTitle_create.call(this);
  143.         },
  144.  
  145.         /**
  146.          * We wait, until the video has finished loading. This must only be done once, since the video is
  147.          * cached in memory (better don't use big videos ^^).
  148.          */
  149.         isReady: function() {
  150.             return _ready && _sceneTitle_isReady.call(this);
  151.         },
  152.  
  153.         /**
  154.          * On start, rewind the video to position 0 and start playing. It will automatically loop, once it
  155.          * has finished.
  156.          */
  157.         start: function() {
  158.             _sceneTitle_start.call(this);
  159.             _video.currentTime = 0;
  160.             _video.play();
  161.         },
  162.  
  163.         /**
  164.          * On stop, pause the video, because otherwise it would continue playing, even through other scenes.
  165.          */
  166.         stop: function() {
  167.             _video.pause();
  168.             _sceneTitle_stop.call(this);
  169.         },
  170.  
  171.         /**
  172.          * Position the video sprite behind the background, so it's possible to put (semi)transparent images
  173.          * above it.
  174.          */
  175.         createBackground: function() {
  176.             this.addChild(_videoSprite);
  177.             _sceneTitle_createBackground.call(this);
  178.         }
  179.  
  180.     });
  181.  
  182. })(this.IAVRA || (this.IAVRA = {}));
Advertisement
Add Comment
Please, Sign In to add comment