设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
12
返回列表 发新帖
楼主: VIPArcher
打印 上一主题 下一主题

[通用发布] 【MV发布】瞎糊一个真·八方向脚本试试js怎么玩

[复制链接]

Lv2.观梦者

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
帖子
839
11
发表于 2015-11-19 14:21:21 | 只看该作者
话说楼主打算做增加帧数的功能么
试了下英文论坛的发现完全冲突,那个破坏力太强了直接把整个行走图划分了读,不是按默认的一个行走图分四个人物的
http://mvplugins.com/plugin/Shaz/More%20Character%20Frames
这种模式跟另外一个待机/走路/跑步的插件也冲突
http://mvplugins.com/plugin/Galv/Galvs%20Character%20Animations

点评

和这样的脚本冲突不是肯定的事嘛=。=  发表于 2015-11-19 14:22
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
帖子
839
12
发表于 2015-11-23 03:34:49 | 只看该作者
折腾了一下把三个行走图脚本整合了
八方向(LZ的),待机动作(如下),增加动画帧数(如下)

增加帧数
http://mvplugins.com/plugin/Shaz/More%20Character%20Frames
待机/行走/跑步动画
http://mvplugins.com/plugin/Galv/Galvs%20Character%20Animations

看脚本的时候就觉得脚本之前没有太多重复定义应该问题不大,果然前两个脚本可以直接共用。问题只在第三个因为一些写法比较暴力。
手写行走图文件名加$似乎是通过MV的内置脚本定义成了大行走图,从MV的编辑器里面都能看出来区别,这种文件不会被划分成4×2的小图。
于是哥折腾了半天稍微做点改动,就可以公用了。。。菜鸟不知道有没有地方有错,还没有测试复杂的图片。

下面是瞎掰的合并了的八方向和增加帧数js,待机动作在这个基础上直接外挂就可以一起用了

JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // VIPArcher_Dir8.js
  3. //=============================================================================
  4. /*:
  5.  * @plugindesc 真 · 八方向移动
  6.  * @author VIPArcher
  7.  *
  8.  * @param Dir8_flag
  9.  * @desc 使用八方向素材的标志
  10.  * @default %
  11.  *
  12.  * @param Dir8_Affix
  13.  * @desc 八方向素材文件后缀
  14.  * @default _8D
  15.  *
  16.  * @help 使用八方向的行走图素材文件名前面添加一个标志,
  17.  * 与之对应的8方向的素材与其同名并在后面添加后缀以区别。
  18.  * 例如默认的设置就是使用八方向的素材命名为:
  19.  * !$%VIPArcher.png
  20.  *
  21.  * 那么与之对应的八方向的素材就应命名为:
  22.  * !$%VIPArcher_8D.png
  23.  *
  24.  */
  25.  
  26. // merge the two plugins
  27. //=============================================================================
  28. // More Character Frames
  29. // by Shaz
  30. // Last Updated: 2015.09.21
  31. //=============================================================================
  32.  
  33. /*:
  34.  * @plugindesc Allows more than 3 Frames
  35.  * @author Shaz
  36.  *
  37.  * @help This plugin does not provide plugin commands.
  38.  *
  39.  * Add [D L R U] to your character sheet name (with $ prefix) to specify haw
  40.  * many frames in each direction (Down, Left, Right, Up).
  41.  * Spritesheets with this added to the file name will use a looping frame
  42.  * animation rather than the back-and-forth default animation.
  43.  *
  44.  * The first frame should be the idle/still pose.
  45.  *
  46.  * eg. $Ralph [8 8 8 8].png
  47.  *     is a character sheet consisting of 4 rows with 8 frames per row.
  48.  *     Animation will go from frame 1 to 8 then start at 1 again.
  49.  *
  50.  *        !!! For merging with idle action plugin, do not put $ in file name. Simply define the frame.
  51.  *     这里不要用插件默认的$前缀文件,为了和其他插件兼容我们要保持MV默认的4*2划分行走图方式
  52.  *     只需要在文件名后面加上[a b c d],分别定义4个方向的帧数
  53.  */
  54.  
  55.  
  56. (function() {
  57.     var parameters = PluginManager.parameters('VIPArcher_Dir8');
  58.     var dir8_flag = String(parameters['Dir8_flag'] || '%');
  59.     var dir8_affix = String(parameters['Dir8_Affix'] || '_8D');
  60.     ImageManager.isDir8Character = function(filename) {
  61.         var reg = new RegExp("^\[\\!\\$\\" + dir8_flag + "]+")
  62.         var sign = filename.match(reg);
  63.         return sign && sign[0].contains(dir8_flag);
  64.     };
  65.  
  66. //multiframe parameters 插入的多帧脚本内容,没有修改
  67.   ImageManager.isMultiFrameCharacter = function(filename) {
  68.     var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
  69.     return frames && frames.length === 5;
  70.   };
  71.  
  72.   ImageManager.getCharacterFrameCount = function(filename) {
  73.     var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
  74.     if (!frames) {
  75.       return [3, 3, 3, 3];
  76.     } else {
  77.       return frames.splice(1, 4);
  78.     }
  79.   };
  80. //multiframe parameters end 插入结束
  81.  
  82.     Game_Player.prototype.moveByInput = function() {
  83.         if (!this.isMoving() && this.canMove()) {
  84.             var direction = Input.dir8
  85.             if (direction > 0) {
  86.                 $gameTemp.clearDestination();
  87.             } else if ($gameTemp.isDestinationValid()){
  88.                 var x = $gameTemp.destinationX();
  89.                 var y = $gameTemp.destinationY();
  90.                 direction = this.findDirectionTo(x, y);
  91.             }
  92.             if (direction > 0) {
  93.                 if (direction % 2 == 0){
  94.                     this.moveStraight(direction);
  95.                     return;
  96.                 }
  97.                 if (direction < 5){
  98.                     this.moveDiagonally(direction + 3 , 2);
  99.                 } else{
  100.                     this.moveDiagonally(direction - 3 , 8);
  101.                 }
  102.             }
  103.         }
  104.     };
  105.     var dir8_move_diagonal = Game_Player.prototype.moveDiagonally;
  106.     Game_Player.prototype.moveDiagonally = function(horz, vert) {
  107.         if (!this.canPass(this._x, this._y, horz) && !this.canPass(this._x, this._y, vert)){
  108.             this.setMovementSuccess(false);
  109.             return;
  110.         }
  111.         if (this.canPass(this._x, this._y, horz) && !this.canPass(this._x, this._y, vert)){
  112.             this.moveStraight(horz);
  113.             return;
  114.         }
  115.         if (this.canPass(this._x, this._y, vert) && !this.canPass(this._x, this._y, horz)){
  116.             this.moveStraight(vert);
  117.             return;
  118.         }
  119.         if (!this.canPassDiagonally(this._x, this._y, horz, vert)) {
  120.             if (Math.random() > 0.5){
  121.                 this.setDirection(vert); this.moveStraight(vert)
  122.             } else {
  123.                 this.setDirection(horz); this.moveStraight(horz)
  124.             }
  125.             return;
  126.         }
  127.         dir8_move_diagonal.call(this, horz, vert);
  128.         if (horz > 5) {
  129.             vert > 5 ? this.setDirection(9) : this.setDirection(7);
  130.         }
  131.         else {
  132.             vert > 5 ? this.setDirection(3) : this.setDirection(1);
  133.         };
  134.     };
  135.     Sprite_Character.prototype.characterPatternY = function() {
  136.         if (this._character.direction() % 2 == 0){
  137.             if (this.dir8_bitmap){ this.bitmap = this.dir4_bitmap; }
  138.             return (this._character.direction() - 2) / 2;
  139.         } else {
  140.             if (this.dir8_bitmap){ this.bitmap = this.dir8_bitmap; }
  141.             return parseInt((this._character.direction() + 1) / 3);
  142.         }
  143.     };
  144.     var dir8_set_CharacterBitmap = Sprite_Character.prototype.setCharacterBitmap
  145.     Sprite_Character.prototype.setCharacterBitmap = function() {
  146.         dir8_set_CharacterBitmap.call(this);
  147.         this._isDir8Character = ImageManager.isDir8Character(this._characterName);
  148.         if (this._isDir8Character) {
  149.             this.dir4_bitmap = this.bitmap;
  150.             this.dir8_bitmap = ImageManager.loadCharacter(this._characterName + dir8_affix);
  151.         };
  152.     };
  153.  
  154. // multiframe code===============插入的多帧代码部分
  155.   var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
  156.   Game_CharacterBase.initMembers = function() {
  157.     _Game_CharacterBase_initMembers.call(this);
  158.     this._isMultiFrame = false;
  159.     this._frames = [3, 3, 3, 3];
  160.   };
  161.  
  162.   var _Game_CharacterBase_maxPattern = Game_CharacterBase.prototype.maxPattern;
  163.   Game_CharacterBase.prototype.maxPattern = function() {
  164.     if (!this._isMultiFrame) {
  165.       return _Game_CharacterBase_maxPattern.call(this);
  166.     } else {
  167. //consider diaganol directions  重写定义 考虑八向脚本兼容
  168.         return this._direction <5 ? this._frames[(parseInt((this._direction + 1)/ 2) - 1)] :  this._frames[(parseInt((this._direction + 1)/ 3))];
  169.     }
  170.   };
  171.  
  172.   var _Game_CharacterBase_pattern = Game_CharacterBase.prototype.pattern;
  173.   Game_CharacterBase.prototype.pattern = function() {
  174.     if (!this._isMultiFrame) {
  175.       return _Game_CharacterBase_pattern.call(this);
  176.     } else {
  177. //      return this._pattern < this._frames[this._direction / 2 - 1] ? this._pattern : 0;
  178. //      为了简单暂时只用了第一行的帧数作为上限,稍微改一下应该就好了,懒,而且应该不太会用到不同方向不同帧数
  179.                 return this._pattern < this._frames[0] ? this._pattern : 0;
  180.     }
  181.   };
  182.  
  183.   var _Game_CharacterBase_isOriginalPattern = Game_CharacterBase.prototype.isOriginalPattern;
  184.   Game_CharacterBase.prototype.isOriginalPattern = function() {
  185.     if (!this._isMultiFrame) {
  186.       return _Game_CharacterBase_isOriginalPattern.call(this);
  187.     } else {
  188.       return this.pattern() === 0;
  189.     }
  190.   };
  191.  
  192.   var _Game_CharacterBase_resetPattern = Game_CharacterBase.prototype.resetPattern;
  193.   Game_CharacterBase.prototype.resetPattern = function() {
  194.     if (!this._isMultiFrame) {
  195.       _Game_CharacterBase_resetPattern.call(this);
  196.     } else {
  197.       this.setPattern(0);
  198.     }
  199.   };
  200.  
  201.   var _Game_CharacterBase_setImage = Game_CharacterBase.prototype.setImage;
  202.   Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
  203.     _Game_CharacterBase_setImage.call(this, characterName, characterIndex);
  204.     this._isMultiFrame = ImageManager.isMultiFrameCharacter(characterName);
  205.     this._frames = ImageManager.getCharacterFrameCount(characterName);
  206.   };
  207.  
  208.   var _Game_CharacterBase_setTileImage = Game_CharacterBase.prototype.setTileImage;
  209.   Game_CharacterBase.prototype.setTileImage = function(tileId) {
  210.     _Game_CharacterBase_setTileImage.call(this, tileId);
  211.     this._isMultiFrame = false;
  212.     this._frames = [3, 3, 3, 3];
  213.   };
  214.  
  215.   Game_CharacterBase.prototype.isMultiFrame = function() {
  216.     return this._isMultiFrame;
  217.   };
  218.  
  219.   Game_CharacterBase.prototype.getDirectionFrames = function() {
  220. //    return this._frames[this._direction / 2 - 1]; 重新定义帧数 兼容八方向
  221.         return this._direction <5 ? this._frames[(parseInt((this._direction + 1)/ 2) - 1)] :  this._frames[(parseInt((this._direction + 1)/ 3))];
  222.   };
  223.  
  224.   var _Game_Event_initMembers = Game_Event.prototype.initMembers;
  225.   Game_Event.prototype.initMembers = function() {
  226.     _Game_Event_initMembers.call(this);
  227.     if (this._isMultiFrame) {
  228.       this._originalPattern = 0;
  229.     }
  230.   };
  231.  
  232.   var _Sprite_Character_patternWidth = Sprite_Character.prototype.patternWidth;
  233.   Sprite_Character.prototype.patternWidth = function() {
  234.     if (!this._character.isMultiFrame()) {
  235.       return _Sprite_Character_patternWidth.call(this);
  236.     } else {
  237. // 除4以还原默认的4*2划分方式
  238.       return this.bitmap.width / (4*this._character.getDirectionFrames());
  239.     }
  240.   };
  241. //doranikofu edit redefine block 原始插件没有重定义的部分,需要按照新定义的行走图动画的帧数去修改index的读取位点,默认是3帧
  242. Sprite_Character.prototype.characterBlockX = function() {
  243.     if (this._isBigCharacter) {
  244.         return 0;
  245.     } else {
  246.         var index = this._character.characterIndex();
  247.         return (index % 4) * (this._character.getDirectionFrames());
  248.     }
  249. };
  250.   //==========
  251.  
  252. })();
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
帖子
839
13
发表于 2015-11-29 15:16:46 | 只看该作者
本帖最后由 doranikofu 于 2015-11-29 16:02 编辑

话说又折腾了一下发现这个只定义了Game_player
貌似对跟随人物和npc都无效吧?。。。
试着把movediagnal从Game_player改高到Game_character或者Game_characterbase都没用。。。这个能通用改到跟随和npc么。。

再就是目前插件是靠读取两个文件分8向,感觉可以考虑整合成一个文件改index实现8向 默认素材就是4×2的 index+4就可以读取下一行的图做斜向图 就看要怎么加进去了
这样不用再读一个文件显示斜向图

点评

最近发现拼图神器 ImageMagick 超级好用。。。拼图神马的完全不是问题  发表于 2015-11-30 00:57
那我改改发到MV区吧。  发表于 2015-11-29 16:44
嗯。我之前也是想整合一个文件,不过有人说改文件名轻松点,拼一个文件麻烦啥啥啥的。  发表于 2015-11-29 16:42
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-12 16:33

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表