-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRP_Afterimage.js
1421 lines (1242 loc) · 40 KB
/
NRP_Afterimage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=============================================================================
// NRP_Afterimage.js
//=============================================================================
/*:
* @target MV MZ
* @plugindesc v2.05 Gives an afterimage effect to the battler or character.
* @author Takeshi Sunagawa (http://newrpg.seesaa.net/)
* @url http://newrpg.seesaa.net/article/483120023.html
*
* @help Gives an afterimage effect to the battler or character.
* The display time, interval, and color tone of the afterimage
* can be adjusted using plugin parameters.
*
* [Basic Usage]
* You can execute the following script
* by specifying the battler (or character) and calling it.
* Basically, it is assumed to be called from DynamicMotion.
* ※a is the battler or character.
*
* ◆a.afterimage().start();
* Start the afterimage.
*
* ◆a.afterimage().end();
* End the afterimage.
* ※If omitted in battle,
* it will be automatically terminated when the action is finished.
* ※Note that it does not automatically exit on the map.
*
* ◆Example for DynamicMotion
* ---------------------------------
* <D-Motion:near>
* script = a.afterimage().start();
* </D-Motion>
*
* <D-Motion:attack>
* script = a.afterimage().end();
* </D-Motion>
*
* <D-Animation/>
* <D-Motion:return/>
* ---------------------------------
*
* ◆Example for Movement Route
* It is easy to write a script as follows.
* > this.afterimage().start();
*
* When finished, it will look like this
* > this.afterimage().end();
*
* It is exactly the same, except that it targets "this" instead of "a".
*
* [Option]
* Normally, the plugin parameter settings are used,
* but the settings can be changed for each skill.
*
* ◆a.afterimage().setInterval(4);
* Set the display interval of the afterimage to 4 frames (4/60 seconds).
*
* ◆a.afterimage().setDuration(30);
* Set the display duration of the afterimage to 30 frames (30/60 seconds).
*
* ◆a.afterimage().setOpacity(128);
* Set the initial opacity of the afterimage to 128/255.
*
* ◆a.afterimage().setColor([255, 255, 255, 255]);
* Set the color tone of the afterimage to [255, 255, 255, 255].
* ※Red, green, blue, strength in that order.
*
* ◆a.afterimage().setBlendMode(1);
* Change the afterimage blending method to 1:Add.
* ※0:Normal, 1:Add, 2:Multiply, 3:Screen
*
* ◆Example for DynamicMotion
* Set the options after the start process as shown below.
*
* ---------------------------------
* <D-Motion:near>
* script = a.afterimage().start(); a.afterimage().setInterval(1); a.afterimage().setDuration(100); a.afterimage().setOpacity(128); a.afterimage().setColor([255, 0, 0, 255]); a.afterimage().setBlendMode(1);
* </D-Motion>
*
* <D-Motion:attack>
* script = a.afterimage().end();
* </D-Motion>
*
* <D-Animation/>
* <D-Motion:return/>
* ---------------------------------
*
* [Reference]
* The following plugin was used as a reference in the creation of this plugin.
*
* SAN_ResidualSprites.js (Sanshiro)
* https://github.com/rev2nym/SAN_ResidualSprites
*
* [Terms]
* There are no restrictions.
* Modification, redistribution freedom, commercial availability,
* and rights indication are also optional.
* The author is not responsible,
* but will deal with defects to the extent possible.
*
* @param Duration
* @type number
* @default 30
* @desc The time it takes for the afterimages to disappear.
*
* @param Interval
* @type number
* @default 4
* @desc The interval at which the afterimages are generated, set in 1/60 second increments.
*
* @param Opacity
* @type number
* @max 255
* @default 255
* @desc The opacity of the afterimages when they are created.
*
* @param Color
* @type string
* @default [0, 0, 0, 0]
* @desc The color tone of the afterimages. eg: [128, 128, 255, 255]
*
* @param BlendMode
* @type select
* @option 0:Normal @value 0
* @option 1:Add @value 1
* @option 2:Multiply @value 2
* @option 3:Screen @value 3
* @default 0
* @desc How to blend afterimages.
*/
/*:ja
* @target MV MZ
* @plugindesc v2.05 バトラー&キャラクターに残像効果を付与します。
* @author 砂川赳(http://newrpg.seesaa.net/)
* @url http://newrpg.seesaa.net/article/483120023.html
*
* @help バトラーまたはキャラクターに対して残像効果を付与します。
* 残像の表示時間、間隔、色調などをプラグインパラメータで調整可能です。
*
* ■基本的な使用法
* バトラーまたはキャラクターを指定して、
* 以下のスクリプトを呼び出すことで実行できます。
* 基本的にはDynamicMotionから呼び出すことを想定しています。
* ※aはバトラーまたはキャラクターです。
*
* ◆a.afterimage().start();
* 残像を開始する。
*
* ◆a.afterimage().end();
* 残像を終了する。
* ※戦闘時に省略した場合、アクション終了時に自動で終了します。
* ※マップ上では自動終了しないので注意してください。
*
* ◆DynamicMotionの記述例
* ---------------------------------
* <D-Motion:near>
* script = a.afterimage().start();
* </D-Motion>
*
* <D-Motion:attack>
* script = a.afterimage().end();
* </D-Motion>
*
* <D-Animation/>
* <D-Motion:return/>
* ---------------------------------
*
* ◆移動ルートの設定の記述例
* スクリプトで以下のように記述するのが手軽です。
* > this.afterimage().start();
*
* 終了時は以下のようになります。
* > this.afterimage().end();
*
* aではなくthisを対象にする以外は全く同じです。
*
* ■オプション
* 通常はプラグインパラメータの設定値を使用しますが、
* スキル毎に設定を変更することもできます。
*
* ◆a.afterimage().setInterval(4);
* 残像の表示間隔を4フレーム(4/60秒)に設定する。
*
* ◆a.afterimage().setDuration(30);
* 残像の表示時間を30フレーム(30/60秒)に設定する。
*
* ◆a.afterimage().setOpacity(128);
* 残像の初期不透明度を128/255に設定する。
*
* ◆a.afterimage().setColor([255, 255, 255, 255]);
* 残像の色調を[255, 255, 255, 255]に設定する。
* ※赤、緑、青、強さの順番
*
* ◆a.afterimage().setBlendMode(1);
* 残像の合成方法を1:加算に変更する。
* ※0:通常, 1:加算, 2:乗算, 3:スクリーン
*
* ◆DynamicMotionの記述例
* 以下のように開始処理の後でオプションを設定してください。
*
* ---------------------------------
* <D-Motion:near>
* script = a.afterimage().start(); a.afterimage().setInterval(1); a.afterimage().setDuration(100); a.afterimage().setOpacity(128); a.afterimage().setColor([255, 0, 0, 255]); a.afterimage().setBlendMode(1);
* </D-Motion>
*
* <D-Motion:attack>
* script = a.afterimage().end();
* </D-Motion>
*
* <D-Animation/>
* <D-Motion:return/>
* ---------------------------------
*
* ■参考
* このプラグインの制作に当たって、
* 以下のプラグインを参考にさせていただきました。
*
* SAN_ResidualSprites.js(サンシロ様)
* https://github.com/rev2nym/SAN_ResidualSprites
*
* ■利用規約
* 特に制約はありません。
* 改変、再配布自由、商用可、権利表示も任意です。
* 作者は責任を負いませんが、不具合については可能な範囲で対応します。
*
* @param Duration
* @text 表示時間
* @type number
* @default 30
* @desc 残像が消滅するまでの時間です。
*
* @param Interval
* @text 間隔
* @type number
* @default 4
* @desc 残像を生成する間隔です。1/60秒単位で設定してください。
*
* @param Opacity
* @text 不透明度
* @type number
* @max 255
* @default 255
* @desc 残像を生成する際の不透明度です。
*
* @param Color
* @text 色調
* @type string
* @default [0, 0, 0, 0]
* @desc 残像の色調です。例:[128, 128, 255, 255]
*
* @param BlendMode
* @text 合成方法
* @type select
* @option 0:通常 @value 0
* @option 1:加算 @value 1
* @option 2:乗算 @value 2
* @option 3:スクリーン @value 3
* @default 0
* @desc 残像の合成方法です。
*/
(function() {
"use strict";
function toBoolean(str, def) {
if (str === true || str === "true") {
return true;
} else if (str === false || str === "false") {
return false;
}
return def;
}
function toNumber(str, def) {
if (str == undefined || str == "") {
return def;
}
return isNaN(str) ? def : +(str || def);
}
function setDefault(str, def) {
if (str == undefined || str == "") {
return def;
}
return str;
}
const PLUGIN_NAME = "NRP_Afterimage";
const parameters = PluginManager.parameters(PLUGIN_NAME);
const pDuration = toNumber(parameters["Duration"], 30);
const pInterval = toNumber(parameters["Interval"], 4);
const pOpacity = toNumber(parameters["Opacity"], 255);
const pColor = parameters["Color"];
const pBlendMode = toNumber(parameters["BlendMode"], 0);
// 残像IDの連番
let mAfterimageSeq = 0;
//-----------------------------------------------------------------------------
// Battler_Afterimage
//
// バトラーの残像を管理するクラス
function Battler_Afterimage() {
this.initialize(...arguments);
}
Battler_Afterimage.prototype = Object.create(Game_Battler.prototype);
Battler_Afterimage.prototype.constructor = Battler_Afterimage;
/**
* ●初期化
*/
Battler_Afterimage.prototype.initialize = function(battler) {
// 紐付け用の残像IDを設定する。
this._afterimageId = mAfterimageSeq;
battler._afterimageId = mAfterimageSeq;
// 連番を加算
mAfterimageSeq++;
};
/**
* ●残像の親となるバトラーを取得する。
*/
Battler_Afterimage.prototype.battler = function() {
return BattleManager.allBattleMembers().find(battler => battler._afterimageId == this._afterimageId);
};
/**
* ●残像処理の開始
*/
Battler_Afterimage.prototype.start = function() {
// 間隔チェック用のカウンタ
this._checkInterval = 0;
// 表示時間
this._duration = pDuration;
// 表示間隔
this._interval = pInterval;
// 標準の不透明度
this._opacity = pOpacity;
// 色調
if (pColor) {
this._color = eval(pColor);
}
// 合成方法
this._blendMode = pBlendMode;
const spriteset = getSpriteset();
let battlerSprite = spriteset.findTargetSprite(this.battler());
// タイミングによってはアクターを取得できないことがあるので、更新して再取得
if (!battlerSprite && this.battler().isActor() && spriteset.updateActors) {
spriteset.updateActors();
battlerSprite = spriteset.findTargetSprite(this.battler());
}
battlerSprite._afterimages = [];
battlerSprite._makeAfterimage = true;
this._isActive = true;
};
/**
* ●残像処理の終了
*/
Battler_Afterimage.prototype.end = function() {
const battlerSprite = getSpriteset().findTargetSprite(this.battler());
battlerSprite._makeAfterimage = false;
this._isActive = false;
};
/**
* ●残像作成チェック
*/
Battler_Afterimage.prototype.check = function() {
if (!this.isActive()) {
return false;
}
let check = false;
if (this._checkInterval == 0) {
check = true;
}
this._checkInterval++;
if (this._checkInterval >= this._interval) {
this._checkInterval = 0;
}
return check;
};
/**
* ●残像を実行中かどうか?
*/
Battler_Afterimage.prototype.isActive = function() {
return this._isActive;
};
/**
* ●表示時間を取得
*/
Battler_Afterimage.prototype.duration = function() {
return this._duration;
};
/**
* ●表示時間を設定
*/
Battler_Afterimage.prototype.setDuration = function(duration) {
this._duration = duration;
};
/**
* ●間隔を取得
*/
Battler_Afterimage.prototype.interval = function() {
return this._interval;
};
/**
* ●間隔を設定
*/
Battler_Afterimage.prototype.setInterval = function(interval) {
this._interval = interval;
};
/**
* ●不透明度を取得
*/
Battler_Afterimage.prototype.opacity = function() {
return this._opacity;
};
/**
* ●不透明度を設定
*/
Battler_Afterimage.prototype.setOpacity = function(opacity) {
this._opacity = opacity;
};
/**
* ●色調を取得
*/
Battler_Afterimage.prototype.color = function() {
return this._color;
};
/**
* ●色調を設定
*/
Battler_Afterimage.prototype.setColor = function(color) {
this._color = color;
};
/**
* ●合成方法を設定
*/
Battler_Afterimage.prototype.blendMode = function() {
return this._blendMode;
};
/**
* ●合成方法を設定
*/
Battler_Afterimage.prototype.setBlendMode = function(blendMode) {
this._blendMode = blendMode;
};
//-----------------------------------------------------------------------------
// Sprite_BattlerAfterimage
//
// アクターの残像となるスプライトクラス
function Sprite_BattlerAfterimage() {
this.initialize(...arguments);
}
Sprite_BattlerAfterimage.prototype = Object.create(Sprite_Battler.prototype);
Sprite_BattlerAfterimage.prototype.constructor = Sprite_BattlerAfterimage;
Sprite_BattlerAfterimage.prototype.initialize = function(parent) {
Sprite.prototype.initialize.call(this);
this.initMembers();
this._parent = parent;
this.setBattler(parent._battler);
};
/**
* ●更新
*/
Sprite_BattlerAfterimage.prototype.update = function() {
// 不透明度を減算
this.opacity -= (this._initialOpacity / this._duration);
};
/**
* ●不透明度の設定
*/
Sprite_BattlerAfterimage.prototype.setOpacity = function(opacity) {
this.opacity = opacity;
};
/**
* ●初期不透明度の設定
*/
Sprite_BattlerAfterimage.prototype.setInitialOpacity = function(opacity) {
this._initialOpacity = opacity;
};
/**
* ●持続時間の設定
*/
Sprite_BattlerAfterimage.prototype.setDuration = function(duration) {
this._duration = duration;
};
/**
* ●位置の設定
*/
Sprite_BattlerAfterimage.prototype.setPosition = function(x, y) {
this.x = x;
this.y = y;
};
//-----------------------------------------------------------------------------
// Sprite_ActorAfterimage
//
// アクターの残像となるスプライトクラス
function Sprite_ActorAfterimage() {
this.initialize(...arguments);
}
Sprite_ActorAfterimage.prototype = Object.create(Sprite_BattlerAfterimage.prototype);
Sprite_ActorAfterimage.prototype.constructor = Sprite_ActorAfterimage;
/**
* ●初期化
*/
Sprite_ActorAfterimage.prototype.initMembers = function() {
Sprite_Battler.prototype.initMembers.call(this);
this._battlerName = "";
this._motion = null;
this._motionCount = 0;
this._pattern = 0;
this.createMainSprite();
};
/**
* ●本体生成
*/
Sprite_ActorAfterimage.prototype.createMainSprite = function() {
Sprite_Actor.prototype.createMainSprite.call(this);
};
/**
* ●バトラーの設定
*/
Sprite_ActorAfterimage.prototype.setBattler = function(battler) {
Sprite_Battler.prototype.setBattler.call(this, battler);
this._actor = battler;
};
/**
* ●画像の設定
*/
Sprite_ActorAfterimage.prototype.setBitmap = function() {
Sprite_Actor.prototype.updateBitmap.call(this);
}
/**
* ●画像の切抜位置の設定
* ※関数名がかぶるので適当
*/
Sprite_ActorAfterimage.prototype.setSetFrame = function() {
// 本体のモーション&パターンを反映
this._motion = this._parent._motion;
this._pattern = this._parent._pattern;
Sprite_Actor.prototype.updateFrame.call(this);
};
//-----------------------------------------------------------------------------
// Sprite_EnemyAfterimage
//
// アクターの残像となるスプライトクラス
function Sprite_EnemyAfterimage() {
this.initialize(...arguments);
}
Sprite_EnemyAfterimage.prototype = Object.create(Sprite_BattlerAfterimage.prototype);
Sprite_EnemyAfterimage.prototype.constructor = Sprite_EnemyAfterimage;
/**
* ●初期化
*/
Sprite_EnemyAfterimage.prototype.initMembers = function() {
Sprite_Battler.prototype.initMembers.call(this);
this._enemy = null;
this._appeared = false;
this._battlerName = "";
this._battlerHue = 0;
this._effectType = null;
this._effectDuration = 0;
this._shake = 0;
};
/**
* ●バトラーの設定
*/
Sprite_EnemyAfterimage.prototype.setBattler = function(battler) {
Sprite_Battler.prototype.setBattler.call(this, battler);
this._enemy = battler;
};
/**
* ●画像の設定
*/
Sprite_EnemyAfterimage.prototype.setBitmap = function() {
Sprite_Enemy.prototype.updateBitmap.call(this);
}
/**
* ●画像の読込
*/
Sprite_EnemyAfterimage.prototype.loadBitmap = function(name) {
Sprite_Enemy.prototype.loadBitmap.call(this, name);
};
/**
* ●色相の設定
*/
Sprite_EnemyAfterimage.prototype.setHue = function(hue) {
Sprite_Enemy.prototype.setHue.call(this, hue);
};
/**
* ●表示の設定
*/
Sprite_EnemyAfterimage.prototype.initVisibility = function() {
// 何もしない
};
/**
* ●画像の切抜位置の設定
* ※関数名がかぶるので適当
*/
Sprite_EnemyAfterimage.prototype.setSetFrame = function() {
// 何もしない
};
//-----------------------------------------------------------------------------
// BattleManager
//-----------------------------------------------------------------------------
/**
* ●変数初期化
*/
const _BattleManager_initMembers = BattleManager.initMembers;
BattleManager.initMembers = function() {
_BattleManager_initMembers.apply(this, arguments);
// 戦闘の度に残像連番をクリア
mAfterimageSeq = 0;
};
//-----------------------------------------------------------------------------
// Game_Battler
//-----------------------------------------------------------------------------
/**
* 【独自】残像管理情報の取得
*/
Game_Battler.prototype.afterimage = function() {
// 外部プラグインなどでonBattleStartを経由しなかった場合、
// undefinedの可能性があるので初期化する。
if (!this._afterimage) {
this._afterimage = new Battler_Afterimage(this);
}
return this._afterimage;
};
/**
* ●戦闘開始時
*/
const _Game_Battler_onBattleStart = Game_Battler.prototype.onBattleStart;
Game_Battler.prototype.onBattleStart = function(advantageous) {
this._afterimage = new Battler_Afterimage(this);
_Game_Battler_onBattleStart.apply(this, arguments);
}
/**
* ●アクション実行終了(バトラー共通)
*/
const _Game_Battler_performActionEnd = Game_Battler.prototype.performActionEnd;
Game_Battler.prototype.performActionEnd = function() {
const afterimage = this.afterimage();
// 残像実行中なら終了
if (afterimage.isActive()) {
afterimage.end();
}
_Game_Battler_performActionEnd.call(this);
};
//-----------------------------------------------------------------------------
// Game_Actor
//-----------------------------------------------------------------------------
/*
* Game_Actor側の関数が未定義の場合は事前に定義
* ※これをしておかないと以後のGame_Battler側への追記が反映されない。
*/
if (Game_Actor.prototype.onBattleEnd == Game_Battler.prototype.onBattleEnd) {
Game_Actor.prototype.onBattleEnd = function() {
return Game_Battler.prototype.onBattleEnd.apply(this, arguments);
}
}
/**
* ●戦闘終了時
*/
const _Game_Actor_onBattleEnd = Game_Actor.prototype.onBattleEnd;
Game_Actor.prototype.onBattleEnd = function() {
_Game_Actor_onBattleEnd.apply(this, arguments);
// 不要変数の初期化
// ※セーブデータに含まない。
this._afterimage = undefined;
};
//-----------------------------------------------------------------------------
// Spriteset_Battle
//-----------------------------------------------------------------------------
/**
* ●更新処理
*/
const _Spriteset_Battle_update = Spriteset_Battle.prototype.update;
Spriteset_Battle.prototype.update = function() {
// removeChild処理を伴うため、個別のupdateに追加するのではなく、
// 先にまとめて処理を行う。
// ※要素数が変化するため、処理が飛ばされるSpriteが発生してしまう。
this.updateAfterimage();
_Spriteset_Battle_update.apply(this, arguments);
};
/**
* 【独自】残像の更新処理
*/
Spriteset_Battle.prototype.updateAfterimage = function() {
for (const sprite of this.battlerSprites()) {
sprite.updateAfterimage();
}
};
//-----------------------------------------------------------------------------
// Sprite_Battler
//-----------------------------------------------------------------------------
/**
* 【独自】残像の状態更新
*/
Sprite_Battler.prototype.updateAfterimage = function() {
if (!this._makeAfterimage || !this._afterimages) {
return;
}
// 不透明度が0以下になった残像を消去
const newAfterimages = [];
for (const afterimage of this._afterimages) {
// 不透明度が有効な残像だけを新配列に追加
if (afterimage.opacity > 0) {
newAfterimages.push(afterimage);
// それ以外は削除
} else {
this.parent.removeChild(afterimage);
}
}
this._afterimages = newAfterimages;
// 残像管理クラスを取得
const afterimageManage = this._battler.afterimage();
if (afterimageManage.check()) {
// 新しい残像を追加
this.createAfterimage();
}
}
/**
* 【独自】残像を作成する。
*/
Sprite_Battler.prototype.createAfterimage = function() {
// 残像管理クラスを取得
const afterimageManage = this._battler.afterimage();
// 新しい残像を作成
let afterimage;
if (this._actor) {
afterimage = new Sprite_ActorAfterimage(this);
} else {
afterimage = new Sprite_EnemyAfterimage(this);
}
const bodyMainSprite = getMainSprite(this);
const afterimageMainSprite = getMainSprite(afterimage);
// 初期不透明度
afterimage.setInitialOpacity(afterimageManage.opacity());
afterimage.setOpacity(afterimageManage.opacity());
// 持続時間
afterimage.setDuration(afterimageManage.duration());
// 本体の情報をコピー
afterimage.setPosition(this.x, this.y);
afterimage.setBitmap();
afterimage.setSetFrame();
afterimage.scale = this.scale;
afterimage.rotation = this.rotation;
afterimage.anchor.x = this.anchor.x;
afterimage.anchor.y = this.anchor.y;
afterimageMainSprite.anchor.x = bodyMainSprite.anchor.x;
afterimageMainSprite.anchor.y = bodyMainSprite.anchor.y;
// 色調設定
const colorTone = afterimageManage.color()
if (colorTone) {
afterimage.setColorTone(colorTone);
}
// 合成方法
afterimage.blendMode = afterimageManage.blendMode();
// Z座標
afterimage.z = this.z;
// 表示優先度の調整のため本体より下に
afterimage.spriteId = this.spriteId - 0.1;
// DynamicMotionの空中Y座標
afterimage._airY = this._airY;
// 基準点(回転軸)が変更されている場合はズレるので調整
if (afterimageMainSprite.anchor.y == 0.5) {
// scaleの変更を考慮
afterimage.x -= afterimage.width/2 * afterimage.scale.x * Math.sin(afterimage.rotation);
afterimage.y += afterimage.height/2 * afterimage.scale.y * Math.cos(afterimage.rotation);
}
// animatedSVEnemies.jsで動作させている場合は反転
if (this._battler._animated) {
afterimage.scale.x *= -1;
}
this._afterimages.push(afterimage);
// 戦闘画面に追加
this.parent.addChild(afterimage);
};
/**
* 【独自】残像を消去する。
*/
Sprite_Battler.prototype.removeAfterimage = function() {
for (const afterimage of this._afterimages) {
this.parent.removeChild(afterimage);
}
this._afterimages = [];
};
//-----------------------------------------------------------------------------
// Character_Afterimage
//
// キャラクターの残像を管理するクラス
function Character_Afterimage() {
this.initialize(...arguments);
}
Character_Afterimage.prototype = Object.create(Game_Character.prototype);
Character_Afterimage.prototype.constructor = Character_Afterimage;
Character_Afterimage.prototype.initialize = function() {
};
/**
* ●残像の元となる本体スプライトを取得
*/
Character_Afterimage.prototype.originalSprite = function() {
const spriteset = getSpriteset();
return spriteset._characterSprites.find(sprite => sprite._character.afterimage() == this);
};
/**
* ●残像処理の開始
*/
Character_Afterimage.prototype.start = function() {
// 間隔チェック用のカウンタ
this._checkInterval = 0;
// 表示時間
this._duration = pDuration;
// 表示間隔
this._interval = pInterval;
// 標準の不透明度
this._opacity = pOpacity;
// 色調
if (pColor) {
this._color = eval(pColor);
}
// 合成方法
this._blendMode = pBlendMode;
const characterSprite = this.originalSprite();
characterSprite._afterimages = [];
this._isActive = true;
};
/**
* ●残像処理の終了
*/
Character_Afterimage.prototype.end = function() {
this._isActive = false;
};
/**
* ●残像作成チェック
*/
Character_Afterimage.prototype.check = function() {
if (!this.isActive()) {
return false;
}
let check = false;
if (this._checkInterval == 0) {
check = true;
}
this._checkInterval++;
if (this._checkInterval >= this._interval) {
this._checkInterval = 0;
}
return check;
};
/**
* ●残像を実行中かどうか?
*/
Character_Afterimage.prototype.isActive = function() {
return this._isActive;
};
/**
* ●表示時間を取得
*/
Character_Afterimage.prototype.duration = function() {
return this._duration;
};
/**
* ●表示時間を設定
*/
Character_Afterimage.prototype.setDuration = function(duration) {
this._duration = duration;
};
/**
* ●間隔を取得
*/
Character_Afterimage.prototype.interval = function() {
return this._interval;
};
/**
* ●間隔を設定
*/
Character_Afterimage.prototype.setInterval = function(interval) {
this._interval = interval;
};
/**
* ●不透明度を取得
*/
Character_Afterimage.prototype.opacity = function() {
return this._opacity;
};
/**
* ●不透明度を設定
*/
Character_Afterimage.prototype.setOpacity = function(opacity) {
this._opacity = opacity;
};