| 赞 | 14 |
| VIP | |
| 好人卡 | |
| 积分 | 23 |
| 经验 | |
| 最后登录 | 2026-7-11 |
| 在线时间 | 178 小时 |
- 梦石
- 0
- 星屑
- 2299
- 在线时间
- 178 小时
- 注册时间
- 2023-11-16
- 回帖
- 76
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 kyjoke 于 2024-5-12 13:33 编辑
虽然我看着这正则表达式没错,但是我写^3_Constrain_%[1-60].png的时候,他录入的却是%[1-1],导致动画序列帧没办法正常播放,有大佬帮我看看哪里有问题吗?
下面是创建图层的脚本调用:
SceneManager._scene.SetLayer(0, "^3_Constrain_%[1-1].png", 255, 1.0, 1.0, 0, 0, 0, true, 0, [0, 0, 0, 0]);
[pre lang="javascript"](function() {
var fs = require('fs'); // 引入文件系统模块
var path = require('path'); // 引入路径模块
var directoryPath = path.join(process.cwd(), 'img/pictures'); // 获取当前工作目录下的图片文件夹路径
var KY_reg = /^\^.*$/; // 初步确认需要使用的文件,匹配以^开头的图片
var KY_imageNames = fs.readdirSync(directoryPath).filter(function(file) {
return KY_reg.test(file);
}); // 初步筛选出^开头的文件名
var KY_scenes = [Scene_Title, Scene_Menu, Scene_Map, Scene_Battle]; // 定义需要添加立绘的场景
KY_scenes.forEach(function(scene) { // 对每个场景进行处理
var originalStart = scene.prototype.start; // 保存原始的start方法
var originalUpdate = scene.prototype.update; // 保存原始的update方法
scene.prototype.sprites = {}; // 在场景的原型中定义sprites对象
scene.prototype.start = function() { // 重写start方法
originalStart.call(this); // 调用原始的start方法
this.createPortraitWindow(); // 创建立绘窗口
};
scene.prototype.update = function() { // 重写update方法
originalUpdate.call(this); // 调用原始的update方法
this.updateSprite(); // 更新精灵
};
scene.prototype.createPortraitWindow = function() { // 初始化创建立绘窗口的方法
var windowX = 0; // 窗口的x坐标
var windowY = 0; // 窗口的y坐标
var windowWidth = 0; // 窗口的宽度
var windowHeight = 0; // 窗口的高度
this.KY_PortraitWindow = new Window_Base(windowX, windowY, windowWidth,
windowHeight); // 创建窗口
this.addWindow(this.KY_PortraitWindow); // 将窗口添加到场景中
this.KY_PortraitWindow.setBackgroundType(2); // 设置窗口的背景类型
};
scene.prototype.updateSprite = function() {// 每帧更新精灵的方法
if (Graphics.frameCount % 1 == 0) {//确保一帧只更新一次
this.children.forEach(function(child) { // 遍历场景的所有子对象
if (child instanceof Sprite && child.bitmaps && child.bitmaps.length > 0) { // 如果子对象是精灵,并且有位图
if (child.isAnimation) { // 如果精灵是序列帧动画
if (child.frameCount % child.playSpeed === 0) { // 如果当前帧计数器是播放速度的倍数
if(child.frameCount >= child.MaxframeCount || !child.frameCount){ //如果当前帧大于最大帧
child.frameCount = 1; // 重新开始循环
console.log("重新开始动画");
}
child.frameCount++; // 帧序列号加一
}
child.bitmap = child.bitmaps[child.frameCount]; // 播放动画
console.log("动画帧: " + child.frameCount);
console.log("最大动画帧: " + child.MaxframeCount);
} else { // 如果精灵不是动画
child.bitmap = child.bitmaps[0]; // 设置精灵的位图为第一帧
}
}
}, this);
}
};
// 修改窗口的脚本调用
scene.prototype.updatePortraitWindow = function(windowX, windowY, windowWidth, windowHeight) {
if (this.KY_PortraitWindow) { // 如果窗口存在
this.KY_PortraitWindow.move(windowX, windowY, windowWidth,windowHeight); // 重新设置窗口的位置和大小
}
};
// 删除窗口的脚本调用
scene.prototype.deletePortraitWindow = function() {
this.removeWindow(this.KY_PortraitWindow); // 从场景中删除窗口
this.KY_PortraitWindow = null; // 清除窗口引用
};
// 创建图层的脚本调用
scene.prototype.SetLayer = function(layerId, imageName, opacity, scaleX, scaleY, x, y, rotation,visible, blendMode, blendColor) {
var sprite = new Sprite(); // 创建一个新的精灵
sprite.layerId = layerId; // 设置精灵的层级id
sprite.imageName = imageName; // 设置图片文件名
sprite.opacity = opacity; // 设置精灵的透明度,范围是0(完全透明)到255(完全不透明)
sprite.scale.x = scaleX; // 设置精灵的x缩放
sprite.scale.y = scaleY; // 设置精灵的y缩放
sprite.x = x; // 设置精灵的x位置,这将决定精灵在屏幕上的位置
sprite.y = y; // 设置精灵的y位置,这将决定精灵在屏幕上的位置
sprite.rotation = rotation; // 旋转角度
sprite.visible = visible; // 设置精灵的可见性,true表示可见,false表示不可见
sprite.blendMode = blendMode; // 设置精灵的混合模式,0: 普通, 1: 加法, 2: 乘法, 3: 屏幕
sprite.setBlendColor(blendColor); // 设置精灵的颜色混合
sprite.bitmaps = []; // 创建一个空数组用于存储位图
sprite.isAnimation = imageName.includes('%'); // 判断精灵是否为动画
var imageNameWithoutExtension = imageName.replace('.png', ''); // 去掉文件名的.png后缀,否则rm会判断为.png.png
var imageId = imageNameWithoutExtension.match(/\^(\d+)/)[1]; // 从文件名中提取图片id,每个id独立
var animationName = imageNameWithoutExtension.split('_')[1]; // 从文件名中提取动画名称,确认动画
var bitmap = ImageManager.loadBitmap('img/pictures/',imageNameWithoutExtension, 0, true); // 加载图片
if (!this.sprites[animationName]) { // 如果精灵对象中不存在该动画名称的精灵
this.sprites[animationName] = sprite; // 将动画精灵添加到精灵对象中
this.sprites[animationName].bitmaps.push(bitmap); // 将位图添加到精灵的位图数组中
}
if (sprite.isAnimation) {//确认精灵为动画时解析动画参数
var frameInfo = imageNameWithoutExtension.match(/%\[(\d+)-(\d+)\]/);//解析%[]里的参数
sprite.frameCount = parseInt(frameInfo[1]);//初始化帧序列号
sprite.MaxframeCount = parseInt(frameInfo[2]);//初始化最大序列帧
sprite.playSpeed = 1;//初始化播放速度
}
this.addChild(sprite); // 将精灵添加到场景中
};
// 删除图层的脚本调用
scene.prototype.deleteLayer = function(layerId) {
var sprite = this.sprites[layerId]; // 获取精灵
if (sprite) { // 如果精灵存在
this.removeChild(sprite); // 从场景中删除精灵
delete this.sprites[layerId]; // 从精灵对象中删除精灵
}
};
// 修改序列帧动画的脚本调用
scene.prototype.updateAnimationFrame = function(layerId, frameCount,playSpeed) {
var sprite = this.sprites[layerId]; // 获取精灵
if (sprite && sprite.isAnimation) { // 如果精灵存在,并且是动画
sprite.frameCount = frameCount; // 设置序列帧
sprite.playSpeed = playSpeed;// 设置播放速度
}
};
});
})();[/pre] |
|