How do I draw multiple text boxes onto the screen?
Here are the Global Variables I am using, they where initiated in main.js once.
//global variables
var player = "key"
var player_sprite = "char_key1"
var font = GetSystemFont();
var window = LoadWindowStyle("window1.rws");
var sh = GetScreenHeight();
var sw = GetScreenWidth();
var move = false;
I created a MsgBox Object
function MsgBox(txt,x,y,w,h,xo,yo) {
//properties for MsgBox
this.window = window;
this.font = font;
this.color_1 = CreateColor(0,255,255,255);
this.color_2 = CreateColor(255,255,255,255);
this.draw = function ()//draw method
{
while(!IsKeyPressed(KEY_X))
{
RenderMap();
this.window.drawWindow(x,y,w,h);
this.font.drawTextBox(xo,y,w,h,yo,txt);
FlipScreen();
}
}
}
In an Update Script I am running the following code so that the message box will draw where the player is not standing
e.g draw the MsgBox right if the player is more left from the centre of the screen.
draw the MsgBox left if the player is more right from the centre of the screen.
var player_x = GetPersonX(player);
var player_y = GetPersonY(player);
var msg = [];
msg[0] =new MsgBox(txt[0],4,4,64,96,4,0);
msg[1] =new MsgBox(txt[0],sw-68,4,64,96,sw-68,0);
if (IsKeyPressed(KEY_Z) && move == false)
if (player_x >= sw/2)
{
msg[0].draw();
}
else if (player_x < sw/2)
{
msg[1].draw();
}
It works fine and they are no problems with the object and how the MsgBox is drawn
But what if I want to draw two MsgBoxes at the same time e.g one for issuing commands and the other for player basic stats
when IsKeyPressed(KEY_Z) is true.
I tried using a for loop to handle drawing multiple MsgBoxes
for(var i=0;i<1;++i){msg[i].draw();}
But it would only draw the first MsgBox in the loop.