My game plays in landscape mode, only. This is the function I use for displaying a message, the passed in i_txt is for a text object created during the initialization for the game (some bits have been extracted as not necessary to demonstrate usage, the MSG_BOX_BUTT sprite is also created at initialization):
void displayMessage(int i_algn,int i_col,float w_mul,float h_mul,int i_butt,int i_txt)
{
// add a virtual button, make it the full size of the display but invisible
createVirtualButton(i_butt,theGame.msgButtX, theGame.msgButtY, TA_GAM_WID_FL);
// set the color
agk::SetSpriteColor(MSG_BOX_BUTT, g_msg_col[i_col].i_rc,g_msg_col[i_col].i_gc,g_msg_col[i_col].i_bc, 255);
// figure out height and width for box
float bw = TA_GAM_WID_FL * w_mul;
float bh = TA_GAM_HIH_FL * h_mul;
agk::SetSpriteSize(MSG_BOX_BUTT,bw,bh);
// set the depth and visibility
agk::SetSpriteVisible(MSG_BOX_BUTT, 1);
agk::SetSpriteDepth(MSG_BOX_BUTT, DISPLAY_MESSAGE_DEPTH);
// recalculate maximum width for text
float mw = 0.85f * bw;
float mh = 0.85f * bh;
// set the text alignment
agk::SetTextAlignment(i_txt, i_algn);
// set the maximum width, so that the text wraps
agk::SetTextMaxWidth(i_txt,mw);
// add the text and make it visible
agk::SetTextString(i_txt,com_frm);
agk::SetTextVisible(i_txt,1);
// we may need to adjust the height of the message box
float th = agk::GetTextTotalHeight(i_txt);
// what is the desired height
//float desw = mw * 1.25f;
float desh = th * 1.25f;
// compare button and box height
float hdiff = bh - th;
if (hdiff > (bh - mh))
{
// adjust box height to be smaller
bh = desh;
agk::SetSpriteSize(MSG_BOX_BUTT,bw,bh);
} else {
// we might be not tall enough
if (hdiff < 0.0)
{
// we need to make the box taller and/or wider
float maxh = 0.9f * TA_GAM_HIH_FL;
float maxw = 0.9f * TA_GAM_WID_FL;
// try making taller
if (desh <= maxh)
{
// use the desired height
bh = desh;
agk::SetSpriteSize(MSG_BOX_BUTT,bw,bh);
} else {
// we need to adjust the width of the box
// make it as wide as possible
bw = maxw;
bh = maxh;
mw = 0.85f * bw;
agk::SetTextMaxWidth(i_txt,mw);
agk::SetSpriteSize(MSG_BOX_BUTT,bw,bh);
agk::SetTextString(i_txt,com_frm);
}
}
}
// set the position for the text
mh = 0.85f * bh;
float y = theGame.msgButtY - (mh / 2.0f);
float x = 0.0f;
switch(i_algn)
{
case 0: x = theGame.msgButtX - (mw / 2.0f); break;
case 1: x = theGame.msgButtX; break;
case 2: x = theGame.msgButtX + (mw / 2.0f); break;
}
agk::SetTextPosition(i_txt, x, y);
}
Cheers,
Ancient Lady
AGK Community Tester