【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

相关文章

vue监听属性watch的用法及使用场景详解

《vue监听属性watch的用法及使用场景详解》watch是vue中常用的监听器,它主要用于侦听数据的变化,在数据发生变化的时候执行一些操作,:本文主要介绍vue监听属性watch的用法及使用场景... 目录1. 监听属性 watch2. 常规用法3. 监听对象和route变化4. 使用场景附Watch 的

Java 缓存框架 Caffeine 应用场景解析

《Java缓存框架Caffeine应用场景解析》文章介绍Caffeine作为高性能Java本地缓存框架,基于W-TinyLFU算法,支持异步加载、灵活过期策略、内存安全机制及统计监控,重点解析其... 目录一、Caffeine 简介1. 框架概述1.1 Caffeine的核心优势二、Caffeine 基础2

防止Linux rm命令误操作的多场景防护方案与实践

《防止Linuxrm命令误操作的多场景防护方案与实践》在Linux系统中,rm命令是删除文件和目录的高效工具,但一旦误操作,如执行rm-rf/或rm-rf/*,极易导致系统数据灾难,本文针对不同场景... 目录引言理解 rm 命令及误操作风险rm 命令基础常见误操作案例防护方案使用 rm编程 别名及安全删除

Spring Security 前后端分离场景下的会话并发管理

《SpringSecurity前后端分离场景下的会话并发管理》本文介绍了在前后端分离架构下实现SpringSecurity会话并发管理的问题,传统Web开发中只需简单配置sessionManage... 目录背景分析传统 web 开发中的 sessionManagement 入口ConcurrentSess

99%的人都选错了! 路由器WiFi双频合一还是分开好的专业解析与适用场景探讨

《99%的人都选错了!路由器WiFi双频合一还是分开好的专业解析与适用场景探讨》关于双频路由器的“双频合一”与“分开使用”两种模式,用户往往存在诸多疑问,本文将从多个维度深入探讨这两种模式的优缺点,... 在如今“没有WiFi就等于与世隔绝”的时代,越来越多家庭、办公室都开始配置双频无线路由器。但你有没有注

深入解析Java NIO在高并发场景下的性能优化实践指南

《深入解析JavaNIO在高并发场景下的性能优化实践指南》随着互联网业务不断演进,对高并发、低延时网络服务的需求日益增长,本文将深入解析JavaNIO在高并发场景下的性能优化方法,希望对大家有所帮助... 目录简介一、技术背景与应用场景二、核心原理深入分析2.1 Selector多路复用2.2 Buffer

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()怎么