Drawing pictures to represent TP values - Causing LAg

wrigty12

Just a QAer playing with Javascript
Veteran
Joined
Jan 11, 2014
Messages
624
Reaction score
159
First Language
English
Primarily Uses
RMMZ
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.
 

Jeremy Cannady

Coldfire
Veteran
Joined
Oct 25, 2015
Messages
449
Reaction score
268
First Language
English
Have you tried to see if a block transfer is less laggy?
 

Amuseum

Veteran
Veteran
Joined
Oct 27, 2015
Messages
71
Reaction score
66
First Language
English Chinese
Primarily Uses
RMXP
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;}
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top