Drawing pictures to represent TP values - Causing LAg

I have this plugin to display a picture that represents the actor's current TP. For instance, every 10 TP the player has, 1 "dot" is drawn, up to 8 dots (80TP).

However, after 1 turn in battle, it begins to lag at an exponential rate. I am guessing that it is because of the rate the game is drawing the images.

I am not fluent in JavaScript, only have learned some things from what I see in other plugins.

Here is a portion of code:

Tp_bar_dot = new Sprite_Base(); if(b1rate == 0.8){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots8");} else if(b1rate >= 0.7){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots7");} else if(b1rate >= 0.6){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots6");} else if(b1rate >= 0.5){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots5");} else if(b1rate >= 0.4){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots4");} else if(b1rate >= 0.3){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots3");} else if(b1rate >= 0.2){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots2");} else if(b1rate >= 0.1){ Tp_bar_dot = new Sprite_Base(); Tp_bar_dot.bitmap = ImageManager.loadPicture("tpdots1");} this.removeChild(Tp_bar_dot); this.addChild(Tp_bar_dot);This is in the function in a usermade script that draws a separate TP bar based on Actor1's TP. It is called everytime Window_Base.update is called.

Is there a way I can do this without causing lag? I can post the entire code if need be.
Have you tried to see if a block transfer is less laggy?
why are you calling imagemanager.load every frame? just load them once and save them in bitmap array. then when you need to render, blt the bitmap.

ex.

Code:
Window_Example.prototype.initialize = function() {	....	this.loadTPSprites();	...	}Window_Example.prototype.loadTPSprites = function() {	this._bitmaps = [];	for (var i=0; i<=10; i++) {		this._bitmaps[i] = ImageManager.loadPicture("tpdots" + i);	}}Window_Example.prototype.refresh = function() {	this.contents.clear();	...	this.drawTPDots();	...}Window_Example.prototype.drawTPDots = function() {	var n = Math.floor(tp / tpmax * 10); // put correct formula here	this.blt( this._bitmaps[n], srcx, srcy, width, height, windowx, windowy);}
if you want to use sprite children instead of blt, add all the children once. then each frame, just toggle their visibility instead of removing and adding. however, i haven't worked with sprites much, so YMMV. something like this:
Code:
Window_Example.prototype.drawTPDots = function() {	var n = Math.floor(tp / tpmax * 10); // put correct formula here	for (var i=0; i<=10; i++) {		// turn off each TPdot		this._bitmaps[i].visible = false;	}	// now turn on the dots we want	this._bitmaps[n].visible = true;}
wow - you are creating and loading sprites on every frame? No wonder it's laggy!

I would create them all at the start of battle and load all the sprites. Then during battle just change their visibility depending on how many you want shown.

Original thread: https://forums.rpgmakerweb.com/threads/drawing-pictures-to-represent-tp-values-causing-lag.49558/