【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

相关文章

Python主动抛出异常的各种用法和场景分析

《Python主动抛出异常的各种用法和场景分析》在Python中,我们不仅可以捕获和处理异常,还可以主动抛出异常,也就是以类的方式自定义错误的类型和提示信息,这在编程中非常有用,下面我将详细解释主动抛... 目录一、为什么要主动抛出异常?二、基本语法:raise关键字基本示例三、raise的多种用法1. 抛

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

Java 枚举的基本使用方法及实际使用场景

《Java枚举的基本使用方法及实际使用场景》枚举是Java中一种特殊的类,用于定义一组固定的常量,枚举类型提供了更好的类型安全性和可读性,适用于需要定义一组有限且固定的值的场景,本文给大家介绍Jav... 目录一、什么是枚举?二、枚举的基本使用方法定义枚举三、实际使用场景代替常量状态机四、更多用法1.实现接

java -jar命令运行 jar包时运行外部依赖jar包的场景分析

《java-jar命令运行jar包时运行外部依赖jar包的场景分析》:本文主要介绍java-jar命令运行jar包时运行外部依赖jar包的场景分析,本文给大家介绍的非常详细,对大家的学习或工作... 目录Java -jar命令运行 jar包时如何运行外部依赖jar包场景:解决:方法一、启动参数添加: -Xb

C/C++ chrono简单使用场景示例详解

《C/C++chrono简单使用场景示例详解》:本文主要介绍C/C++chrono简单使用场景示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友... 目录chrono使用场景举例1 输出格式化字符串chrono使用场景China编程举例1 输出格式化字符串示

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

Java集成Onlyoffice的示例代码及场景分析

《Java集成Onlyoffice的示例代码及场景分析》:本文主要介绍Java集成Onlyoffice的示例代码及场景分析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 需求场景:实现文档的在线编辑,团队协作总结:两个接口 + 前端页面 + 配置项接口1:一个接口,将o

Python Flask 库及应用场景

《PythonFlask库及应用场景》Flask是Python生态中​轻量级且高度灵活的Web开发框架,基于WerkzeugWSGI工具库和Jinja2模板引擎构建,下面给大家介绍PythonFl... 目录一、Flask 库简介二、核心组件与架构三、常用函数与核心操作 ​1. 基础应用搭建​2. 路由与参

IDEA实现回退提交的git代码(四种常见场景)

《IDEA实现回退提交的git代码(四种常见场景)》:本文主要介绍IDEA实现回退提交的git代码(四种常见场景),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.已提交commit,还未push到远端(Undo Commit)2.已提交commit并push到

QT6中绘制UI的两种方法详解与示例代码

《QT6中绘制UI的两种方法详解与示例代码》Qt6提供了两种主要的UI绘制技术:​​QML(QtMeta-ObjectLanguage)​​和​​C++Widgets​​,这两种技术各有优势,适用于不... 目录一、QML 技术详解1.1 QML 简介1.2 QML 的核心概念1.3 QML 示例:简单按钮