Simple Confetti Plugin
Hi! I have made a simple Confetti Effect script (first script, with the help of ChatGPTdata:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7) and after some struggling it works.I would like to share it with you. Maybe it can help someone...
// ==Plugin==
// @name confetti
// @desc A plugin to add colorful confetti effect to the game.
// ==/Plugin==
(function() {
var confettiEnabled = false;
var confettiContainer = null;
var shouldStopConfetti = false; // New variable
var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
if (confettiEnabled && !shouldStopConfetti) { // Check shouldStopConfetti
this.startConfettiEffect();
}
};
var _Scene_Map_terminate = Scene_Map.prototype.terminate;
Scene_Map.prototype.terminate = function() {
_Scene_Map_terminate.call(this);
shouldStopConfetti = true; // Set to true when scene terminates
this.stopConfettiEffect();
};
Scene_Map.prototype.startConfettiEffect = function() {
var confettiContainer = new Sprite();
confettiContainer.z = 10;
this.addChild(confettiContainer);
var confettiImages = ['confetti', 'confetti2', 'confetti3'];
var numConfetti = 100;
for (var i = 0; i < numConfetti; i++) {
var confettiImage = confettiImages;
var confetti = new Sprite(ImageManager.loadPicture(confettiImage));
confetti.x = Math.random() * Graphics.width;
confetti.y = -Math.random() * 200;
confetti.anchor.x = 0.5;
confetti.anchor.y = 0.5;
confetti.rotationSpeed = Math.random() * 0.1 - 0.05;
confetti.fallSpeed = Math.random() * 2 + 2;
confetti.tilt = Math.random() * 30 - 15;
confetti.blendMode = PIXI.BLEND_MODES.ADD;
confettiContainer.addChild(confetti);
}
confettiContainer.update = function() {
for (var i = 0; i < this.children.length; i++) {
var confetti = this.children;
confetti.rotation += confetti.rotationSpeed;
confetti.y += confetti.fallSpeed;
confetti.x += Math.sin(confetti.rotation) * confetti.tilt;
if (confetti.y > Graphics.height) {
confetti.x = Math.random() * Graphics.width;
confetti.y = -10;
}
}
};
};
Scene_Map.prototype.stopConfettiEffect = function() {
if (confettiContainer) {
this.removeChild(confettiContainer);
confettiContainer = null;
}
};
})();
Usage:
To activate script you use SCRIPT command on an event and paste this code:
SceneManager._scene.startConfettiEffect();
If you call the event multiple times... more confetti. Pretty simple.
The effect is auto-disables when you leave the map
You need to have images for the confetti on your /img/pictures/ folder. Their name should be confetti.png, confetti2.png, and confetti3.png. You can change this or add more images or whatever editing this line of the script:
var confettiImages = ['confetti', 'confetti2', 'confetti3'];
I used these three images, you can use them, or edit them or whatever you want. Same with the code. Use it, edit it, improve it, I dont really care.
Greetings, friends!
本贴来自国际rpgmaker官方论坛作者:EdenM处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/simple-confetti-plugin.160525/
页:
[1]