RPG Maker Forums

I why i have array incrementation when i use clearTimeout


Example whit this code


AvatarFrame[1] = 0; // the TimeOut store in this array

function Avatar1(WhatToDo) {
clearTimeout(timerAvatar[1]); // clear the timeOut Array
if (WhatToDo == 'Stop') { return;} // If call Avatar1('Stop'), this stop the function
timerAvatar[1] = setTimeout(function() { // give timeout to the array timerAvatar[1]
console.log(timerAvatar[1]); // this show the timeOut ID valur ?? i think
console.log('Avatar 1 framme'); // show TXT for fun in the SetTimeout
Avatar1(); }, 3); // CallBack Function and End of TimeOut
}


So when i call 


Avatar1();


Or


AvatarAnim(1,0,'Talk'); // in other function


This give my animation


View attachment 52434


And i notice a reduction in fps and the console.log incremented array ???.


clearTimeout.gif
I go from 120 to 109 FPS. With 


setInterval



Do you have sugestions to help me to optimise this.
That TimeOut Function i use is badly written or mismanaged by RPGmaker.
If I use the Parallels Event to display the animation directly.
I do not notice any drop in FPS


Thank you for your clarification.
This is an example for testing.
Here is the complete plugin.

/*:
*
*@plugindesc Gestion des menue
*
*
@author Djmisterjon

*@help
*Lorsque click sur menue mais aussi le menue des dées
*
*
*/
// trick
//SceneManager.preferableRendererType = function() { return 'canvas'; }; Change perfec blend mode ( affiche les bon mode blend)
//=============================================================================
// Game_BOOT
//Booting all variable function and array.
//=============================================================================
console.log('awfdaf');
//=============================================================================
// Game Variable
//=============================================================================
AvatarFrame = [];
AvatarFrame[1] = 0; // frame toujours en evolution pour avatar 0 a 12
AvatarFrame[2] = 0; // frame toujours en evolution pour avatar 0 a 12
timerAvatar = [];
AvatarInterval = [];
oldAvatarID = [];
oldAvatarID[1] = 8; // default picture id avatar 1
oldAvatarID[2] = 9; // default picture id avatar 2
AvatarDefXy = [];
AvatarDefXy[1] = [100,650];
AvatarDefXy[2] = [220,765];

//=============================================================================
// Game arrays & objets
//=============================================================================

//=============================================================================
// Game avatar Function
//=============================================================================
//


function AvatarAnim(Avatar, ID, WhatToDo, Ax, Ay, TalkingType) {
clearInterval(AvatarInterval[Avatar]);
AvatarInterval[Avatar] = 0;
clearTimeout(timerAvatar[Avatar]);
timerAvatar[Avatar] = 0;
//Si dans le call function utilise 0 affiche au meme ID que avant ex: AvatarAnim(1,0,'Talk');
if (ID == 0) {
ID = oldAvatarID[Avatar];
}
// Si acient id nest pas egal ces que on a changer le ID Donc supprimer ancient ID
else if (oldAvatarID[Avatar] !== ID) {
var OldX = $gameScreen.picture(oldAvatarID[Avatar])._x; // utile permet de faire un MoveTo en changean de ID
var OldY = $gameScreen.picture(oldAvatarID[Avatar])._y;
$gameScreen.erasePicture(oldAvatarID[Avatar]);
$gameScreen.showPicture(ID, 'H' + Avatar + '-IDLE-' + AvatarFrame[Avatar], 1, OldX, OldY, 100, 100, 255, 0);
}
oldAvatarID[Avatar] = ID;


if (WhatToDo == 'SHOW') {
$gameScreen.showPicture(ID, 'H' + Avatar + '-IDLE-talking-happy-6', 1, Ax - 280, Ay, 100, 100, 255, 0);
$gameScreen.picture(ID)._angle = -50;
new IAVRA.ANIMATE.Tween($gameScreen.picture(ID), { _x: Ax,_angle: 0 }).easing(IAVRA.EASING.back.out).duration(25).start();
$gameScreen.setPictureCallCommon(ID, 2, 1); // lorsque click sur image call BAG
timerAvatar[Avatar] = setTimeout(function() {
$gameScreen.showPicture(ID, 'H' + Avatar + '-IDLE-0', 1, $gameScreen.picture(ID)._x, $gameScreen.picture(ID)._y, 100, 100, 255, 0);
AvatarAnim(Avatar, ID, 'ANIM', Ax, Ay);
}, 420);
} else if (WhatToDo == 'ANIM') {
AvatarInterval[Avatar] = setInterval(function() {
if (AvatarFrame[Avatar] > 12) {
AvatarFrame[Avatar] = 0;
}
$gameScreen.showPicture(ID, 'H' + Avatar + '-IDLE-' + AvatarFrame[Avatar], 1, $gameScreen.picture(ID)._x, $gameScreen.picture(ID)._y, 100, 100, 255, 0);
AvatarFrame[Avatar]++;
}, 58);
} else if (WhatToDo == 'Talk') {
// liste des type expresions parlotes
if (TalkingType == 0 || TalkingType == null) {
TalkingType = 'happy-';
}
// jouer expression
AvatarInterval[Avatar] = setInterval(function() {
if (AvatarFrame[Avatar] > 12) {
AvatarFrame[Avatar] = 0;
}
$gameScreen.showPicture(ID, 'H' + Avatar + '-IDLE-talking-' + TalkingType + AvatarFrame[Avatar], 1, $gameScreen.picture(ID)._x, $gameScreen.picture(ID)._y, 100, 100, 255, 0);
AvatarFrame[Avatar]++;
console.log('Avatar1Interval==== ' + AvatarInterval[Avatar]);
}, 58);
timerAvatar[Avatar] = setTimeout(function() {
AvatarAnim(Avatar, ID, 'ANIM', Ax, Ay);
}, 2350);

}
else if (WhatToDo == 'MoveTo') {
if (Ax == null) {Ax = $gameScreen.picture(ID)._x;} // si rien entré ces que on bouge pas X
if (Ay == null) {Ay = $gameScreen.picture(ID)._y;}// si rien entré ces que on bouge pas Y
if (Ay == null) {Ay = $gameScreen.picture(ID)._y;}// si rien entré ces que on bouge pas Y
new IAVRA.ANIMATE.Tween($gameScreen.picture(ID), { _x: Ax,_y: Ay ,_scaleX:TalkingType }).easing(IAVRA.EASING.quart.out).duration(50).start();
timerAvatar[Avatar] = setTimeout(function() {
AvatarAnim(Avatar, ID, 'ANIM', Ax, Ay);
}, 800);
}
else if (WhatToDo == 'CallBag') {
new IAVRA.ANIMATE.Tween($gameScreen.picture(ID), { _x: $gameScreen.picture(ID)._x+120,_scaleX: -100 }).easing(IAVRA.EASING.back.out).duration(25).start();
new IAVRA.ANIMATE.Tween($gameScreen.picture(ID+1), { _x: $gameScreen.picture(ID+1)._x+185,_scaleX: -100 }).easing(IAVRA.EASING.back.out).duration(25).start();
SliderOption('SHOW');
}
}


//=============================================================================
// Game_Interpreter
//=============================================================================





Tank you

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,038
Messages
1,018,466
Members
137,821
Latest member
Capterson
Top