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

Project1

 找回密码
 注册会员
搜索
查看: 4410|回复: 8
打印 上一主题 下一主题

[有事请教] 如何再initialize多一次?

[复制链接]

Lv2.观梦者

梦石
0
星屑
853
在线时间
168 小时
注册时间
2012-12-1
帖子
46
跳转到指定楼层
1
发表于 2019-5-23 15:23:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
10星屑
插件里有一行脚本是

Sprite_Equipment.prototype.initialize = function (spriteChar, equip) {
    Sprite_Base.prototype.initialize.call(this);

用事件让主角换装后,我是用脚本让主角重新进入同一个地图同一个位置,就能刷新换好的装备sprite了

CurrentX = $gamePlayer._realX-$gamePlayer._x
CurrentY = $gamePlayer._realY-$gamePlayer._y+0.5
$gamePlayer.reserveTransfer($gameMap._mapId,$gamePlayer._x,$gamePlayer._y,$gamePlayer._direction,2)

但是重新进入地图会顿两秒,有没有什么方法可以重新运行这个插件?或者重新initialize多一次?

最佳答案

查看完整内容

一行代码刷新所有 Sprite_Character(主角、跟随、事件等) 设置完装备后在地图执行这句就行了

Lv4.逐梦者

梦石
0
星屑
9617
在线时间
566 小时
注册时间
2017-9-28
帖子
208
2
发表于 2019-5-23 15:23:03 | 只看该作者
一行代码刷新所有 Sprite_Character(主角、跟随、事件等)
  1. SceneManager._scene._spriteset._characterSprites.forEach(function(c) { c.setCharacter(c._character) })
复制代码
设置完装备后在地图执行这句就行了

点评

膜拜!非常完美  发表于 2019-5-23 22:55
喵喵喵
回复

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
17965
在线时间
2165 小时
注册时间
2015-7-4
帖子
919
3
发表于 2019-5-23 16:11:31 | 只看该作者
看不太懂意思,不过刷新角色图像可以试一下这个:
$gamePlayer.refresh();

点评

试过了,不行,他是bitmap  发表于 2019-5-23 16:14
回复

使用道具 举报

Lv2.观梦者

梦石
0
星屑
853
在线时间
168 小时
注册时间
2012-12-1
帖子
46
4
 楼主| 发表于 2019-5-23 16:15:50 | 只看该作者
目前用比较绕的方式暂时解决了

Sprite_Equipment.prototype.updateCharacterFrame = function () {

if(this._characterName !== $dataWeapons[3002].meta.graphic.split(',')[0]){
this._characterName = this._equip.meta.graphic.split(',')[0];}
    this.bitmap = ImageManager.loadEquipment(this._characterName, 0)}

目测有效
回复

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9617
在线时间
566 小时
注册时间
2017-9-28
帖子
208
5
发表于 2019-5-23 16:27:54 | 只看该作者
首先不知道你用的是什么插件,没有代码没法直接给回答。
其次当然可以重复调用 initialize,但还是需要插件代码。

点评

麻烦大大看一看  发表于 2019-5-23 16:33
喵喵喵
回复

使用道具 举报

Lv2.观梦者

梦石
0
星屑
853
在线时间
168 小时
注册时间
2012-12-1
帖子
46
6
 楼主| 发表于 2019-5-23 16:32:36 | 只看该作者
hyrious 发表于 2019-5-23 16:27
首先不知道你用的是什么插件,没有代码没法直接给回答。
其次当然可以重复调用 initialize,但还是需要插件 ...
  1. //=============================================================================
  2. // MBS - Visual Equipment
  3. //-----------------------------------------------------------------------------
  4. // por Masked
  5. //=============================================================================
  6. //-----------------------------------------------------------------------------
  7. // Especificações do plugin (Não modifique!)
  8. // Plugin specifications (Do not modify!)
  9. //
  10. /*:
  11. *
  12. * @author Masked
  13. * @plugindesc Shows images on characters depending on their equipments.         
  14. *
  15. * <MBS VisualEquip>
  16. * @help
  17. * =============================================================================
  18. * Introduction
  19. * =============================================================================
  20. * This script creates specific images on characters that makes them look like
  21. * if it really had that items equipped.
  22. *
  23. * =============================================================================
  24. * How to use
  25. * =============================================================================
  26. * You can choose the charset that will represent an item by putting this tag on
  27. * its notes:
  28. *
  29. * <graphic:equip_graphic.png, x>
  30. *
  31. * The "equip_graphic.png" part is the file name, the file have to be placed on
  32. * the folder you choose on the plugin settings. The "x" is the character index,
  33. * if it's a single char (the file name starts with '), set this to 0.
  34. * The equipment charset works the same way as every other charset on the game,
  35. * so you can use $ and ! to specify big characters and stuff.
  36. *
  37. * You can set an offset for the equipment graphic if you want by putting this
  38. * tag on the equip's note:
  39. *
  40. * <offset:x, y>
  41. *
  42. * The "x" and "y" are the horizontal and vertical offset for the equipment
  43. * image.
  44. *
  45. * And last but not least, you can set the equipment graphic's priority for
  46. * showing some equipments above others or even below the character, just
  47. * put this tag on its notes:
  48. *
  49. * <priority:z>
  50. *
  51. * The "z" is the equipment priority, higher priorities make equipments to be
  52. * draw above the others and negative priorities will make it to be drawn
  53. * below the character.
  54. *
  55. * If you want, you can also use the following tag on an event's notes to make
  56. * the script draw equipments on it:
  57. *
  58. * <equips:a id1, w id2, a id3...>
  59. *
  60. * The equipments are specified by using the first letter of the equipment
  61. * type (that is, a for Armor and w for Weapon) followed by its ID. Ex.:
  62. * <equips: a 1, w 2>
  63. *
  64. * In this example, the event would equip the armor with ID 1 and the weapon
  65. * with ID 2 from the database.
  66. *
  67. * =============================================================================
  68. * Credits
  69. * =============================================================================
  70. * - Masked, creator.
  71. *
  72. * @param Equipments Path
  73. * @desc Folder where the equipment charsets will be located.
  74. * @default ./img/equips/
  75. *
  76. */
  77. /*:pt
  78. *
  79. * @author Masked
  80. * @plugindesc Cria imagens sobre o personagem dependendo dos equipamentos dele.
  81. *
  82. * <MBS VisualEquip>
  83. *
  84. * @help
  85. * =============================================================================
  86. * Introdução
  87. * =============================================================================
  88. * Este script cria imagens especiais sobre o personagem que variam de acordo
  89. * com os equipamentos que ele está usando no momento.
  90. *
  91. * =============================================================================
  92. * Utilização
  93. * =============================================================================
  94. * Para definir o nome arquivo de imagem da qual o gráfico do equipamento vem
  95. * adicione nas notas do equipamento:
  96. *
  97. * <graphic:equip_graphic.png, x>
  98. *
  99. * Sendo o 'equip_graphic.png' o nome do arquivo de gráfico na pasta configurada
  100. * no plugin e o 'x' o índice do char dentro do set.
  101. * Os gráficos de equipamento funcionam da mesma forma que os de personagem e os
  102. * prefixos de gráfico ($ e !) também funcionam com ele.
  103. *
  104. * Você pode ainda definir um offset para o equipamento com a tag offset:
  105. *
  106. * <offset:x, y>
  107. *
  108. * Sendo o x e y as cordenadas para o offset. Também pode usar a tag priority
  109. * para colocar equipamentos mais acima ou abaixo na tela:
  110. *
  111. * <priority:z>
  112. *
  113. * Quando maior o z maior a prioridade do equipamento e ele aparece mais acima
  114. * do resto. Índices negativos fazem com que o gráfico apareça abaixo do
  115. * personagem.
  116. *
  117. * Caso queira adicionar um gráfico de equipamento a um evento, adicione nas
  118. * notas dele a tag:
  119. *
  120. * <equips:a id1, w id2, a id3...>
  121. *
  122. * Os ids devem vir precedidos pela inicial do tipo de equipamento seguido por
  123. * um espaço, para armaduras, use 'a id', e para armas use 'w id'. Ex.:
  124. * <equips: a 1, w 2>
  125. *
  126. * Neste exemplo o evento usaria a armadura de ID 1 e arma de ID 2.
  127. * Você pode por quantos IDs quiser, basta separá-los por vírgulas.
  128. *
  129. * =============================================================================
  130. * Créditos
  131. * =============================================================================
  132. * - Masked, por criar
  133. *
  134. * @param Equipments Path
  135. * @desc Caminho da pasta dos arquivos de gráfico de equipamento
  136. * @default ./img/equips/
  137. *
  138. */

  139. var Imported = Imported || {};

  140. var MBS = MBS || {};
  141. MBS.VisualEquipment = {};

  142. "use strict";

  143. (function ($) {

  144.   $.Parameters = $plugins.filter(function(p) {return p.description.contains('<MBS VisualEquip>');})[0].parameters;
  145.   $.Param = $.Param || {};

  146.   //-----------------------------------------------------------------------------
  147.   // Configuração

  148.   // Caminho dos arquivos
  149.   $.Param.path = $.Parameters["Equipments Path"];

  150.   //-----------------------------------------------------------------------------
  151.   // ImageManager
  152.   //
  153.   // Gerenciador de imagens do jogo

  154.   /**
  155.    * Carregamento de uma imagem de equipamento
  156.    * @method loadEquipment
  157.    * @param {String} filename Nome do arquivo
  158.    * @param {Number} hue Matiz do Bitmap
  159.    * @return Retorna um bitmap de uma imagem de equipamento
  160.    */
  161.   ImageManager.loadEquipment = function (filename, hue) {
  162.     return this.loadBitmap($.Param.path, filename, hue, false);
  163.   };

  164.   //-----------------------------------------------------------------------------
  165.   // Sprite_Equipment
  166.   //
  167.   // Sprite de um equipamento

  168.   /**
  169.    * @constructor
  170.    */
  171.   function Sprite_Equipment() {
  172.     this.initialize.apply(this, arguments)
  173.   }

  174.   Sprite_Equipment.prototype = Object.create(Sprite_Base.prototype);
  175.   Sprite_Equipment.prototype.constructor = Sprite_Base;

  176.   /**
  177.    * Inicialização do objeto
  178.    *
  179.    * @method initialize
  180.    * @param {Sprite_Character} spriteChar Sprite do character ao qual o equip pertence
  181.    * @this {Sprite_Equipment}
  182.    */
  183.   Sprite_Equipment.prototype.initialize = function (spriteChar, equip) {
  184.     Sprite_Base.prototype.initialize.call(this);
  185.     this._charSprite = spriteChar;
  186.     this.x = this.y = 0;
  187.     this._charSprite.addChild(this);
  188.     this._equip = equip;
  189.     if (this._equip.meta.offset) {
  190.       this._offset.x = Number(this._equip.meta.offset.split(',')[0]);
  191.       if (this._equip.meta.offset.split(',').length > 1)
  192.         this._offset.y = Number(this._equip.meta.offset.split(',')[1]);
  193.     }
  194.     this.anchor.x = this._charSprite.anchor.x;
  195.     this.anchor.y = this._charSprite.anchor.y;
  196.     this.z = this._charSprite.z + Number(this._equip.meta.priority || 0);
  197.     this._index = Number(this._equip.meta.graphic.split(',')[1]);
  198.     this._characterName = this._equip.meta.graphic.split(',')[0];
  199.     this.bitmap = ImageManager.loadEquipment(this._characterName, 0);
  200.   };

  201.   /**
  202.    * Atualização do objeto
  203.    *
  204.    * @method update
  205.    * @this {Sprite_Equipment}
  206.    */
  207.   Sprite_Equipment.prototype.update = function () {
  208.     Sprite_Base.prototype.update.call(this);
  209.     this.updateCharacterFrame();
  210.   };

  211.   /**
  212.    * Atualização do frame do sprite
  213.    *
  214.    * @method updateFrame
  215.    * @this {Sprite_Equipment}
  216.    */
  217.   Sprite_Equipment.prototype.updateCharacterFrame = function () {
  218.      var isBig = ImageManager.isBigCharacter(this._characterName);

  219.      var pw = isBig ? this.bitmap.width / 3 : this.bitmap.width / 12;
  220.      var ph = isBig ? this.bitmap.height / 4 : this.bitmap.height / 8;

  221.      var sx = ((isBig ? 0 : (this._index % 4 * 3)) + this._charSprite.characterPatternX()) * pw;
  222.      var sy = ((isBig ? 0 : (Math.floor(this._index / 4) * 4)) + this._charSprite.characterPatternY()) * ph;

  223.      this.setFrame(sx, sy, pw, ph);
  224.    };

  225.   //-----------------------------------------------------------------------------
  226.   // Sprite_Character
  227.   //
  228.   // Sprite de um personagem ou evento

  229.   // Alias
  230.   var _Sprite_Character_initMembers = Sprite_Character.prototype.initMembers;

  231.   /**
  232.    * Atualização do bitmap do character
  233.    *
  234.    * @method updateBitmap
  235.    * @this {Sprite_Character}
  236.    */
  237.   Sprite_Character.prototype.initMembers = function() {
  238.     _Sprite_Character_initMembers.call(this);
  239.   };

  240.   // Alias
  241.   var _Sprite_Character_setCharacter = Sprite_Character.prototype.setCharacter;

  242.   /**
  243.    * Definição do character
  244.    *
  245.    * @method updateBitmap
  246.    * @param {Game_Character} character Character usado pelo sprite
  247.    * @this {Sprite_Character}
  248.    */
  249.   Sprite_Character.prototype.setCharacter = function(character) {
  250.     _Sprite_Character_setCharacter.call(this, character);
  251.     this._equipments = [];
  252.     if (this._character instanceof Game_Player) {
  253.       $gameParty.leader().equips().forEach(function (equip) {
  254.         if (equip) {
  255.           if (equip.meta.graphic)
  256.             this._equipments.push(new Sprite_Equipment(this, equip));
  257.         }
  258.       }, this);
  259.     } else if (this._character instanceof Game_Follower) {
  260.       if (this._character.actor()) {
  261.         this._character.actor().equips().forEach(function (equip) {
  262.           if (equip) {
  263.             if (equip.meta.graphic)
  264.               this._equipments.push(new Sprite_Equipment(this, equip));
  265.           }
  266.         }, this);
  267.       }
  268.     } else if (this._character instanceof Game_Event) {
  269.       if (this._character.event().meta.equips) {
  270.         this._character.event().meta.equips.split(',').forEach(function (id) {
  271.           var t = id.trim().split(' ');
  272.           var equip;
  273.           if (t[0] === 'a') {
  274.             equip = $dataArmors[Number(t[t.length - 1])];
  275.           } else if (t[0] === 'w') {
  276.             equip = $dataWeapons[Number(t[t.length - 1])];
  277.           }
  278.           if (equip)
  279.             this._equipments.push(new Sprite_Equipment(this, equip));
  280.         }, this);
  281.       }
  282.     }
  283.   };

  284. })(MBS.VisualEquipment);

  285. Imported["MBS_VisualEquipment"] = 1.0;

  286. if (Imported["MVCommons"]) {
  287.   PluginManager.register("MBS_VisualEquipment", 1.0, "Displays images that represent the equipments characters are using", {  
  288.       email: "[email protected]",
  289.       name: "Masked",
  290.       website: "N/A"
  291.     }, "28-10-2015");
  292. }
复制代码
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-14 05:56

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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