Unlimited and Optimized Pictures handle
Unlimited and Optimized Pictures handleIntroduction
These are just some modifications in the original script.
Features
Remove the auto created (100 default) image objects, and create the image objects dynamically, and when the "erase Picture" is called, it also erase the object.
This doesn't create a object with empty values, it only relocate space for the used images.
So, even if you use, "$gameScreen.showPicture(9999999,"Image_Name", 0, x, y, 100, 100, 255, 0);" it will not make the variable size 9999999.
How to Use
Just save the script as a .js file and add it to your project.
Plugin Commands / Script Calls
The same from original.
As the engine has a limite of 100 when calling throug "Show Picture", use "$gameScreen.showPicture" function.
Example:
JavaScript:
$gameScreen.showPicture(
id, name, origin, x, y, scaleX, scaleY, opacity, blendMode);
//Like
$gameScreen.showPicture(9999999,"Image_Name", 0, x, y, 100, 100, 255, 0);
You can use any "id" you want.
Like:
JavaScript:
$gameScreen.showPicture("Nun","People2_6", 1, 0, 0, 100, 100, 255, 0);
$gameScreen.showPicture("Doggy","Nature_1", 1, 0, 0, 100, 100, 255, 0);
Script
JavaScript:
var ImageController = undefined;
Game_Screen.prototype.maxPictures = function() {
return 0;// Added Line to remove the auto created pictures object
};
Spriteset_Base.prototype.initialize = function() {
Sprite.prototype.initialize.call(this);
this.setFrame(0, 0, Graphics.width, Graphics.height);
this.loadSystemImages();
this.createLowerLayer();
this.createUpperLayer();
this._animationSprites = [];
ImageController = this; //Added line only to set the ImageController variable
};
Game_Screen.prototype.showPicture = function(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode) {
const realPictureId = this.realPictureId(pictureId);
if(ImageController._pictureContainer.children.find(picture => picture._pictureId == realPictureId) == undefined) {//Added line to check if the picture already exist
ImageController._pictureContainer.addChild(new Sprite_Picture(realPictureId))//Added line to create the picture object and add it to the container
const picture = new Game_Picture();
picture.show(name, origin, x, y, scaleX, scaleY, opacity, blendMode);
picture.id = realPictureId;
if(this._pictures.length > 0)
{
const ThisPictureIndex = this._pictures.indexOf(this._pictures.find(picture => picture === undefined));
if(ThisPictureIndex != -1) {
this._pictures = picture;
return;
} else {
this._pictures.push(picture);
return;
}
}
else
this._pictures.push(picture)
} else {
$gameScreen.erasePicture(realPictureId);
$gameScreen.showPicture(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode);
}
};
Game_Screen.prototype.picture = function(pictureId) {
const realPictureId = this.realPictureId(pictureId);
return this._pictures.find(function(picture) {
if(picture)
return picture.id === realPictureId
else
return false;
});
};
Sprite_Picture.prototype.remove = function() {
this.parent.removeChild(this);
};
Game_Screen.prototype.erasePicture = function(pictureId) {
const realPictureId = this.realPictureId(pictureId);
this._pictures = undefined;
//this._pictures = null;
const picture = ImageController._pictureContainer.children.find(picture => picture._pictureId == realPictureId);
if(picture)
picture.remove(); //Added line to remove the picture object from the container
};
Game_Screen.prototype.realPictureId = function(pictureId) {
return pictureId; //This was changed to only return the same pictureId inserted, function was not removed to keep compatibility with other plugins
};
Terms and Credits
Use it however you like, no need to give me credit, since it's just a modification of the original script.
本贴来自国际rpgmaker官方论坛作者:Naemegashi Yokohuro处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/unlimited-and-optimized-pictures-handle.147871/
页:
[1]