【RPG Maker MV 仿新仙剑 战斗场景UI (五)】

2024-03-21 05:28

本文主要是介绍【RPG Maker MV 仿新仙剑 战斗场景UI (五)】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

RPG Maker MV 仿新仙剑 战斗场景UI 五

  • 战斗状态菜单
    • 原始RMMV 菜单窗口
    • 仿新仙剑代码
    • 仿新仙剑战斗状态菜单

战斗状态菜单

这部分比较简单,由于有主菜单的状态菜单打底所以开发上也容易些。

原始RMMV 菜单窗口

在原版的RMMV中显示的数据主要是人物的HPMPTP、和两个计量条人物姓名,不需要显示的东西可以不进行显示。
在这里插入图片描述
如图显示是很单调的,主菜单的好歹还有个头像,这个就少了一些东西。

仿新仙剑代码


function Window_BattleStatus() {this.initialize.apply(this, arguments);
}Window_BattleStatus.prototype = Object.create(Window_Selectable.prototype);
Window_BattleStatus.prototype.constructor = Window_BattleStatus;Window_BattleStatus.prototype.initialize = function(x,y) {Window_Selectable.prototype.initialize.call(this, x, y, 465, 116);this.characterStateFrame=ImageManager.loadMenu('CharacterStateFrame');this.refresh();
};
Window_BattleStatus._faceWidth=144;
Window_BattleStatus._faceHeight=112;
//标准内边距
Window_BattleStatus.prototype.standardPadding = function() {return 0;//18;
};
Window_BattleStatus.prototype.numVisibleRows = function() {return 1;
};
//设置状态菜单的最大列数
Window_BattleStatus.prototype.maxCols = function() {return 3;
};//最大项目数
Window_BattleStatus.prototype.maxItems = function() {return $gameParty.size();
};
//间距
Window_BattleStatus.prototype.spacing = function() {return 6;
};//每项高度
Window_BattleStatus.prototype.itemHeight = function() {var clientHeight = this.height - this.padding * 2;return Math.floor(clientHeight / this.numVisibleRows());
};Window_BattleStatus.prototype.drawItem = function(index) {this.drawItemImage(index);this.drawItemStatus(index);
};
//绘制人物背景
Window_BattleStatus.prototype.drawItemBackground = function(index) {if (index === this._pendingIndex) {var rect = this.itemRect(index);//var color = this.pendingColor();var color = this.deathColor();this.changePaintOpacity(false);this.contents.fillRect(rect.x, rect.y, rect.width, rect.height, color);this.changePaintOpacity(true);}
};
//绘制人物图像
Window_BattleStatus.prototype.drawItemImage = function(index) {var actors = $gameParty.members();var actor=actors[index];var rect = this.itemRect(index);this.changePaintOpacity(actor.isBattleMember());this.drawActorFace(actor, rect.x + 2, rect.y + 1, rect.width, rect.height,index);this.changePaintOpacity(true);
};//绘制演员头像
Window_BattleStatus.prototype.drawActorFace = function(actor, x, y, width, height,index) {this.drawFace(actor.faceName(), actor.faceIndex(), x, y, width, height,index);
};//绘制头像
Window_BattleStatus.prototype.drawFace = function(faceName, faceIndex, x, y, width, height,index) {var actors=$gameParty.members();var wx=0;switch(actors.length){case 1:wx=154*2;break;case 2:wx=154;break;default:break;}width = width || Window_BattleStatus._faceWidth;height = height || Window_BattleStatus._faceHeight;var bitmap = ImageManager.loadFace(faceName);var pw = Window_BattleStatus._faceWidth;var ph = Window_BattleStatus._faceHeight;var sw = Math.min(width, pw);var sh = Math.min(height, ph);var sx = faceIndex % 6 * pw + (pw - sw) / 2;var sy = Math.floor(faceIndex / 6) * ph + (ph - sh) / 2;if(!bitmap.isReady()){setTimeout(()=>{this.contents.blt(bitmap, sx, sy, sw, sh, x+wx, y);this.drawItemStatus(index);},0.25);}else{this.contents.blt(bitmap, sx, sy, sw, sh, x+wx, y);}
};//绘制人物状态
Window_BattleStatus.prototype.drawItemStatus = function(index) {var actor = $gameParty.members()[index];var rect = this.itemRect(index);this.drawActorSimpleStatus(actor, rect.x,  rect.y, rect.width,rect.height);
};//绘制演员简单状态
Window_BattleStatus.prototype.drawActorSimpleStatus = function(actor, x, y, width,height) {this.drawActorIcons(actor, x+73, y+36,width,height);// 人物状态图标this.drawActorHp(actor, x, y, width);this.drawActorMp(actor, x, y, width);
};//绘制演员图标,作为参考及绘制四种状态
Window_BattleStatus.prototype.drawActorIcons = function(actor, x, y, width) {width = width || 144;var actorStates=actor.states(); //获取人物状态var stateIcons=[];for (var i = 0; i < actorStates.length; i++) {if (actorStates[i].id>13&&actorStates[i].id<18) {stateIcons.push(actorStates[i].iconIndex);}}for (var i = 0; i < stateIcons.length&&i<2; i++) {this.drawIcon(stateIcons[i]-12, x + 24 * i+(i*5), y);}
};
//绘制状态图标
Window_BattleStatus.prototype.drawIcon = function(iconIndex, x, y) {var actors=$gameParty.members();var wx=0;switch(actors.length){case 1:wx=154*2;break;case 2:wx=154;break;default:break;}x=x+wx;var bitmap = ImageManager.loadSystem('CharacterStatus');var pw = 24;var sx = iconIndex % 5 * pw;var sy = 0;if(!bitmap.isReady()){//console.log(bitmap.isReady())setTimeout(()=>{this.contents.blt(bitmap, sx, sy, pw, 26, x, y);},0.25);}else{this.contents.blt(bitmap, sx, sy, pw, 26, x, y);}
};
//绘制演员HP
Window_BattleStatus.prototype.drawActorHp = function(actor, x, y, width) {width = width || 144;var color1 = this.textColor(10);var color2 = this.textColor(15);this.drawCurrentAndMax(actor.hp, actor.mhp, x-2, y+56, width,color1, color2);
};
//绘制演员MP
Window_BattleStatus.prototype.drawActorMp = function(actor, x, y, width) {width = width || 144;var color1 = this.textColor(9);var color2 = this.textColor(15);this.drawCurrentAndMax(actor.mp, actor.mmp, x-10, y+74, width,color1, color2);
};//绘制现在和最大值
Window_BattleStatus.prototype.drawCurrentAndMax = function(current, max, x, y,width, color1, color2) {var actors=$gameParty.members();var wx=0;switch(actors.length){case 1:wx=154*2;break;case 2:wx=154;break;default:break;}x=x+wx;this.contents.fontSize=14;//设置字体大小var labelWidth = this.textWidth('HP');//28var valueWidth = this.textWidth('0000');//56var slashWidth = this.textWidth('/');//14var x1 = x + width - valueWidth;var x2 = x1 - slashWidth;var x3 = x2 - valueWidth;if (x3 >= x + labelWidth) {this.changeTextColor(color1);this.contents.outlineColor=color1;this.contents.outlineWidth = 0;this.drawText(current, x3, y, valueWidth, 'right');this.changeTextColor(color2);this.contents.outlineColor=color2;this.contents.outlineWidth = 0;this.drawText('/', x2, y, slashWidth, 'center');this.changeTextColor(color1);this.contents.outlineColor=color1;//轮廓颜色this.contents.outlineWidth = 0;//轮廓宽度this.drawText(max, x1, y, valueWidth, 'left');} else {this.contents.outlineColor=color1;//轮廓颜色this.contents.outlineWidth = 0;//轮廓宽度this.changeTextColor(color1);this.drawText(current, x1, y, valueWidth, 'left');}
};//绘制文本
Window_BattleStatus.prototype.drawText = function(text, x, y, maxWidth, align) {this.contents.drawText(text, x, y, maxWidth, this.lineHeight(), align);
};
//等待索引
Window_BattleStatus.prototype.pendingIndex = function() {return this._pendingIndex;
};
//刷新光标
Window_BattleStatus.prototype._refreshCursor = function() {var pad = this._padding;var x = this._cursorRect.x;var y = this._cursorRect.y;var w = this._cursorRect.width;var h = this._cursorRect.height;var bitmap = new Bitmap(w, h);this._windowCursorSprite.bitmap = bitmap;this._windowCursorSprite.setFrame(0, 0, w, h);var actors=$gameParty.members();var wx=0;switch(actors.length){case 1:wx=154*2;break;case 2:wx=154;break;default:break;}this._windowCursorSprite.move(wx+x, y);if (w > 0 && h > 0&&this.characterStateFrame) {var csf=this.characterStateFrame;this._windowCursorSprite.bitmap.blt(csf,0,0,164,96,0-3,0+20,164,96);}
};
//更新光标
Window_BattleStatus.prototype._updateCursor = function() {this._windowCursorSprite.bitmap.clear();var blinkCount = this._animationCount % 50;var characterStateSpriteY=0;if (this._windowCursorSprite.visible) {switch(Math.floor(blinkCount/10)){case 0:characterStateSpriteY=0;break;case 1:characterStateSpriteY=96;break;case 2:characterStateSpriteY=192;break;case 3:characterStateSpriteY=288;break;case 4:characterStateSpriteY=384;break;default://characterStateSpriteY=4*96;break;}}this._windowCursorSprite.bitmap.blt(this.characterStateFrame,0,characterStateSpriteY,164,96,0-3,0+20,164,96);this._windowCursorSprite.visible = this.isOpen();
};Window_BattleStatus.prototype.update = function() {Window_Selectable.prototype.update.call(this);this._animationCount++;
};

这里只对其中部分代码做出解释,大部分代码在之前都说过的。
initialize 方法中,调用的父类传入的参数width和主菜单的不同,这是为什么,这是因为主菜单时做的是4角色同框的,而这里是3个角色同框的,后期应该会保持一致。
maxCols 方法中的参数也是这个作用。

	switch(actors.length){case 1:wx=154*2;break;case 2:wx=154;break;default:break;}

这部分代码也是这个作用,重新计算需要绘制图像的位置
_updateCursor 这个更新光标的方法中判断的条件发生了变化,原来是按照是否激活来判断,现在按照是否隐藏来判断,这是因为,默认窗口是取消激活的,而激活后导致的问题就是在使用其他菜单时会操作到这个菜单,因此需要取消激活,但是光标的更新就出现了问题,因此需要更换判断条件。
update 正常来说更新的方法是不用显示的写出来的,因为会自动执行,但里面的代码更新动画的变量是在窗口激活时才进行计数的,因此需要子类显示调用父类后重新进行动画更新计时的增加,不然就不能正常显示。

仿新仙剑战斗状态菜单

如图:
在这里插入图片描述
做出来的样子就是这样的,当然了,现在是暂时没有去掉背景的,后期全部完善战斗场景的窗口和功能后再去掉背景。

这篇关于【RPG Maker MV 仿新仙剑 战斗场景UI (五)】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/831856

相关文章

MySQL常用字符串函数示例和场景介绍

《MySQL常用字符串函数示例和场景介绍》MySQL提供了丰富的字符串函数帮助我们高效地对字符串进行处理、转换和分析,本文我将全面且深入地介绍MySQL常用的字符串函数,并结合具体示例和场景,帮你熟练... 目录一、字符串函数概述1.1 字符串函数的作用1.2 字符串函数分类二、字符串长度与统计函数2.1

Java Stream流之GroupBy的用法及应用场景

《JavaStream流之GroupBy的用法及应用场景》本教程将详细介绍如何在Java中使用Stream流的groupby方法,包括基本用法和一些常见的实际应用场景,感兴趣的朋友一起看看吧... 目录Java Stream流之GroupBy的用法1. 前言2. 基础概念什么是 GroupBy?Stream

java如何实现高并发场景下三级缓存的数据一致性

《java如何实现高并发场景下三级缓存的数据一致性》这篇文章主要为大家详细介绍了java如何实现高并发场景下三级缓存的数据一致性,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 下面代码是一个使用Java和Redisson实现的三级缓存服务,主要功能包括:1.缓存结构:本地缓存:使

C++中detach的作用、使用场景及注意事项

《C++中detach的作用、使用场景及注意事项》关于C++中的detach,它主要涉及多线程编程中的线程管理,理解detach的作用、使用场景以及注意事项,对于写出高效、安全的多线程程序至关重要,下... 目录一、什么是join()?它的作用是什么?类比一下:二、join()的作用总结三、join()怎么

在MySQL中实现冷热数据分离的方法及使用场景底层原理解析

《在MySQL中实现冷热数据分离的方法及使用场景底层原理解析》MySQL冷热数据分离通过分表/分区策略、数据归档和索引优化,将频繁访问的热数据与冷数据分开存储,提升查询效率并降低存储成本,适用于高并发... 目录实现冷热数据分离1. 分表策略2. 使用分区表3. 数据归档与迁移在mysql中实现冷热数据分

WinForm跨线程访问UI及UI卡死的解决方案

《WinForm跨线程访问UI及UI卡死的解决方案》在WinForm开发过程中,跨线程访问UI控件和界面卡死是常见的技术难题,由于Windows窗体应用程序的UI控件默认只能在主线程(UI线程)上操作... 目录前言正文案例1:直接线程操作(无UI访问)案例2:BeginInvoke访问UI(错误用法)案例

nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析(结合应用场景)

《nginx-t、nginx-sstop和nginx-sreload命令的详细解析(结合应用场景)》本文解析Nginx的-t、-sstop、-sreload命令,分别用于配置语法检... 以下是关于 nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析,结合实际应

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

MyBatis-Plus 中 nested() 与 and() 方法详解(最佳实践场景)

《MyBatis-Plus中nested()与and()方法详解(最佳实践场景)》在MyBatis-Plus的条件构造器中,nested()和and()都是用于构建复杂查询条件的关键方法,但... 目录MyBATis-Plus 中nested()与and()方法详解一、核心区别对比二、方法详解1.and()

ModelMapper基本使用和常见场景示例详解

《ModelMapper基本使用和常见场景示例详解》ModelMapper是Java对象映射库,支持自动映射、自定义规则、集合转换及高级配置(如匹配策略、转换器),可集成SpringBoot,减少样板... 目录1. 添加依赖2. 基本用法示例:简单对象映射3. 自定义映射规则4. 集合映射5. 高级配置匹