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

Project1

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

[原创发布] 每天一点技术小文章(1)

[复制链接]

Lv1.梦旅人

梦石
0
星屑
73
在线时间
6 小时
注册时间
2025-4-15
帖子
8
跳转到指定楼层
1
发表于 前天 16:30 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
这个系列主要是给大家讲解一下游戏的一些相关代码。
今天主要是讲解数据库中,角色头像如何映射到菜单界面的头像。




其核心的实现代码在 rmmz_windows.js这个文件
代码复制
  1. Window_Base.prototype.drawFace = function(
  2.     faceName, faceIndex, x, y, width, height
  3. ) {
  4.     width = width || ImageManager.faceWidth;
  5.     height = height || ImageManager.faceHeight;
  6.     const bitmap = ImageManager.loadFace(faceName);
  7.     const pw = ImageManager.faceWidth;
  8.     const ph = ImageManager.faceHeight;
  9.     const sw = Math.min(width, pw);
  10.     const sh = Math.min(height, ph);
  11.     const dx = Math.floor(x + Math.max(width - pw, 0) / 2);
  12.     const dy = Math.floor(y + Math.max(height - ph, 0) / 2);
  13.     const sx = Math.floor((faceIndex % 4) * pw + (pw - sw) / 2);
  14.     const sy = Math.floor(Math.floor(faceIndex / 4) * ph + (ph - sh) / 2);
  15.     this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);
  16. };


在这个代码里,主要要关注的是    const bitmap = ImageManager.loadFace(faceName); 这里是导入图片到bitmap 大家可以在这里去console.log(faceName)会发现这个faceName其实是图片名。
然后因为我们mz格式的图片一般是一整张图片,然后我们去选择做切割,那么这里就通过 const sx = Math.floor((faceIndex % 4) * pw + (pw - sw) / 2);
    const sy = Math.floor(Math.floor(faceIndex / 4) * ph + (ph - sh) / 2); 去确定我们选的是哪张图片,其实就是通过faceIndex去计算,用户选择的那块头像在整块图片的x,y,然后由于每个图像的宽度高度都一致,所以再加上pw、ph,就可以获取那一块图片。
然后通过this.contents.blt去绘制,bitmap是图片,sx,sy是头像的方位,sw,sh是长度宽度,dx,dy是这个头像显示的方位。
有什么不懂的欢迎交流。

Lv2.观梦者

梦石
0
星屑
817
在线时间
83 小时
注册时间
2008-2-4
帖子
69
2
发表于 昨天 18:18 | 只看该作者
到位,虽然用不啊哦
关注 小迷弟,永远不迷路
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-6-30 02:42

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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