Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // Fog
- // by Shaz
- // Last Updated: 2015.10.31
- //=============================================================================
- /*:
- * @plugindesc Adds a fog overlay to maps
- * @author Shaz
- *
- * @help
- *
- * Plugin Command:
- * ChangeFog filename scroll-x scroll-y opacity
- *
- * filename = name of file (no extension) in img/fogs folder
- * scroll-x, scroll-y = amount to scroll each frame (-ve is up/left)
- * could be a number or a formula
- * opacity = fog opacity (0-255)
- *
- */
- (function() {
- var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args) {
- _Game_Interpreter_pluginCommand.call(this, command, args);
- if (command.toUpperCase() === 'CHANGEFOG') {
- $gameMap.changeFog(args);
- };
- };
- ImageManager.loadFog = function(filename, hue) {
- return this.loadBitmap('img/fogs/', filename, hue, true);
- };
- var _Game_Map_initialize = Game_Map.prototype.initialize;
- Game_Map.prototype.initialize = function() {
- _Game_Map_initialize.call(this);
- this._fogName = '';
- this._fogSx = 0;
- this._fogSy = 0;
- this._fogOpacity = 0;
- this._fogX = 0;
- this._fogY = 0;
- };
- var _Game_Map_setup = Game_Map.prototype.setup;
- Game_Map.prototype.setup = function(mapId) {
- _Game_Map_setup.call(this, mapId);
- this.setupFog();
- };
- Game_Map.prototype.setupFog = function() {
- this._fogName = $dataMap.meta.fogName || '';
- this._fogSx = Number($dataMap.meta.fogSx || 0);
- this._fogSy = Number($dataMap.meta.fogSy || 0);
- this._fogOpacity = Number($dataMap.meta.fogOpacity || 0);
- this._fogX = 0;
- this._fogY = 0;
- };
- Game_Map.prototype.changeFog = function(args) {
- this._fogName = args[0];
- this._fogSx = eval(args[1]);
- this._fogSy = eval(args[2]);
- this._fogOpacity = eval(args[3]);
- };
- var _Game_Map_setDisplayPos = Game_Map.prototype.setDisplayPos;
- Game_Map.prototype.setDisplayPos = function(x, y) {
- _Game_Map_setDisplayPos.call(this, x, y);
- if (this.isLoopHorizontal()) {
- this._fogX = x;
- } else {
- this._fogX = this._displayX;
- }
- if (this.isLoopVertical()) {
- this._fogY = y;
- } else {
- this._fogY = this._displayY;
- }
- };
- Game_Map.prototype.fogOx = function() {
- return this._fogX * this.tileWidth() / 2;
- };
- Game_Map.prototype.fogOy = function() {
- return this._fogY * this.tileHeight() / 2;
- };
- Game_Map.prototype.fogName = function() {
- return this._fogName;
- };
- Game_Map.prototype.fogOpacity = function() {
- return this._fogOpacity;
- };
- var _Game_Map_update = Game_Map.prototype.update;
- Game_Map.prototype.update = function(sceneActive) {
- _Game_Map_update.call(this, sceneActive);
- this.updateFog();
- };
- Game_Map.prototype.updateFog = function() {
- this._fogX += this._fogSx / this.tileWidth() / 2;
- this._fogY += this._fogSy / this.tileHeight() / 2;
- };
- var _Spriteset_Map_createLowerLayer = Spriteset_Map.prototype.createLowerLayer;
- Spriteset_Map.prototype.createLowerLayer = function() {
- _Spriteset_Map_createLowerLayer.call(this);
- this.createFog();
- };
- var _Spriteset_Map_update = Spriteset_Map.prototype.update;
- Spriteset_Map.prototype.update = function() {
- _Spriteset_Map_update.call(this);
- this.updateFog();
- };
- Spriteset_Map.prototype.createFog = function() {
- this._fog = new TilingSprite();
- this._fog.move(0, 0, Graphics.width, Graphics.height);
- this._baseSprite.addChild(this._fog);
- };
- Spriteset_Map.prototype.updateFog = function() {
- if (this._fogName !== $gameMap.fogName()) {
- this._fogName = $gameMap.fogName();
- this._fog.bitmap = ImageManager.loadFog(this._fogName);
- }
- if (this._fog.bitmap) {
- this._fog.origin.x = $gameMap.fogOx();
- this._fog.origin.y = $gameMap.fogOy();
- this._fog.opacity = $gameMap.fogOpacity();
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement