Thank you all
I'll figure out which one will be the best way for me.

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote
Well, you can always construct your dynamic sprite the same way that you are doing already, but then set it onto a GUI.BackgroundGraphic rather than creating is as an overlay.
If that doesn't work perhaps you could provide more detail about what you're trying to do.
function room_RepExec(){
if (IsTimerExpired(1) == 1) {
SetBackgroundFrame(Random(4));
SetTimer(1,(Random(33)+40);
}
}
import function display(String txt, int x=-1, int y=-1); // My Display function
.
.
protected int Max_Txt_Pxl_Width; // Maxium width of Desired Text Box Gui
// ******************** My New attempt at a Text box Gui with custom Gui Text Tiles *************************
function SpriteFont::display(String Txt, int x, int y){
int GuiBoxlength=0;
int GuiBoxheight=0;
int MiddleLoop=0; // int for how many Top Middle tiles there are?
this.Max_Txt_Pxl_Width=System.ViewportWidth - (Game.SpriteWidth[233] * 3);
// Set Max text Length wanted. This is half of your Background graphic width
// This will be setted by a function in the future
if ((Txt == null) || (Txt == "")) return; // invalid text parameter, abort
int Txtwidth = this.GetSpriteTextRawWidth(Txt); // Get how long the text Graphics will be.
int Lines = (Txtwidth / (this.Max_Txt_Pxl_Width)); // Find out how many lines will be in the Txt Box
if (Lines == 0){ // if there is only 1 line. Get Box Length and height for sprite.
int TopM=Game.SpriteWidth[234]; // Get Width of Top Middle custom Tile
while(GuiBoxlength<Txtwidth){ // Get full Width of the Box's top middle
GuiBoxlength+=TopM;
MiddleLoop++; // adding how many top middle sprites there are
}
GuiBoxlength+=Game.SpriteWidth[233] * 2; // Add the length of the two Corner end pieces of the top part of the box for Full Width of the Gui Text Box
GuiBoxheight=(Game.SpriteHeight[233] * 2) + Game.SpriteHeight[236]; // Get height by X2 top corner pieces and middle graphic for Full Height of Gui Text Box
}
else{ // Get Sprite size for multiple lines
int TopM=Game.SpriteWidth[234]; // Get Width of Top Middle custom Tile
while(GuiBoxlength<this.Max_Txt_Pxl_Width){ // Get how many Top Middle Tiles there are. This has to be done due to the fact
// that custom Gui tile sizes are difrent lengths
GuiBoxlength+=TopM;
MiddleLoop++; // adding how many top middle sprites there are to match Max_Txt_Pxl_Width
}
GuiBoxlength+=(Game.SpriteWidth[233] * 2); // Add the length of the two end pieces of the top part of the box
GuiBoxheight=(Game.SpriteHeight[233] * 2) + (Game.SpriteHeight[236] * (Lines+1));// Get height by X2 edge pieces pluss height of side middle tile X how many lines their are
}
DynamicSprite *sprite=DynamicSprite.Create(GuiBoxlength, GuiBoxheight); // create a sprite as big as the text box needs to be.
DrawingSurface *TxtBox=sprite.GetDrawingSurface(); // Make a drawing surface to Draw the tiles on too
// Draw The Txt box
int spriteX=0; //create another x and y that we can manipulate to draw onto our txt box
int spriteY=0;
//**************Top Line of Text Box ***********************
TxtBox.DrawImage(spriteX, spriteY, 233); // Draw Top Left Tile Onto the sprite
spriteX+=Game.SpriteWidth[233]; // advance spriteX forward
int i=MiddleLoop;
while(i>0){ //Put the Top Middle Tiles in
TxtBox.DrawImage(spriteX, spriteY, 234);
spriteX+=Game.SpriteWidth[234];
i--;
}
TxtBox.DrawImage(spriteX, spriteY, 235); // Draw top Right Tile
//***********************************************************
//**************Middle Line of Text Box ***********************
int iL=0;
spriteY=0;
while(iL<Lines+1){
spriteX=0;
spriteY+=Game.SpriteHeight[233]; // Move spriteY down
TxtBox.DrawImage(spriteX, spriteY,236); // Draw Middle Left Tile
spriteX+=Game.SpriteWidth[236]; // advance spriteX forward
i=MiddleLoop; // reset i
while(i>0){ //Put the middle Tiles in
TxtBox.DrawImage(spriteX, spriteY, 237); // Draw Middle tile
spriteX+=Game.SpriteWidth[237]; // advance spriteX forward
i--;
}
TxtBox.DrawImage(spriteX, spriteY, 238); // Draw Middle Right Tile
iL++;
}
//***********************************************************
//**************Bottom Line of Text Box ***********************
spriteX=0;
spriteY+=Game.SpriteHeight[236]; // Move spriteY down
TxtBox.DrawImage(spriteX, spriteY,239); // Draw Bottom Left Tile
spriteX+=Game.SpriteWidth[239]; // advance spriteX forward
i=MiddleLoop; // reset i
while(i>0){ //Put the Top Middle Tiles in
TxtBox.DrawImage(spriteX, spriteY, 240); // Draw Bottom Middle tile
spriteX+=Game.SpriteWidth[240]; // advance spriteX forward
i--;
}
TxtBox.DrawImage(spriteX, spriteY, 241); // Draw Bottom Right Tile
//***********************************************************
DynamicSprite *textSprite;
if(Lines == 0){ // if There is only one line then just draw our Txt onto the box
textSprite = this.TextOnSprite(Txt);
TxtBox.DrawImage(Game.SpriteWidth[233], Game.SpriteHeight[233], textSprite.Graphic); // draw our text
textSprite.Delete(); // delete this sprite, we don't need it any more
}
else{ // Do this if there is Multiple lines to our lines of Txt in our box
int LineX=Game.SpriteWidth[233];
int LineY=Game.SpriteHeight[233];
int LineWidth;
int StrStart=0;
int StrCntr=0;
int TempMax=this.Max_Txt_Pxl_Width;
iL=0;
while(iL<Lines+1){
LineWidth=0;
while((LineWidth<TempMax) && (StrCntr<=Txt.Length)){ // Walk down the String Txt and find out
// where StrCntr Stops at the end of the max Width
LineWidth+= this.GetSpriteCharRawWidth(Txt.Chars[StrCntr]) + this.CharSpacing;
StrCntr++;
}
if(Txt.Chars[StrCntr]==' '){ // If the End of the Line at StrCntr is a ' ' (space)
// Draw that line of txt
textSprite = this.TextOnSprite(Txt.Substring(StrStart, (StrCntr-StrStart))); // grab Line Segment out of whole text
TxtBox.DrawImage(LineX, LineY, textSprite.Graphic); // draw our text
textSprite.Delete();
}
else {
while((Txt.Chars[StrCntr]!=' ') && (StrCntr>StrStart) && (StrCntr!=Txt.Length)){ // Walk backwards and find a ' '(space)
StrCntr--;
}
if(StrStart>=StrCntr) StrStart=StrCntr-1; // crash check
textSprite = this.TextOnSprite(Txt.Substring(StrStart, (StrCntr-StrStart))); // grab Line Segment out of whole text
TxtBox.DrawImage(LineX, LineY, textSprite.Graphic); // draw our text
textSprite.Delete();
} // end else of if(Txt.Chars[StrCntr]==' ')
LineY+=this.GetSpriteTextRawHeight(Txt.Substring(StrStart, StrCntr)); // Move LineY down
StrCntr++;
StrStart=StrCntr; // Get StrStart to point that the Begining of the next line
iL++; // incease the line counter by 1
} // end while(iL<Lines+1){
} // end else of if(Lines == 0)
TxtBox.Release(); // Update Memory: release Drawingsurface TxtBox to sprite since we are done
if ((x == -1) && (y == -1)){ // Set Default if no Parm is passed
x = (System.ViewportWidth - sprite.Width) / 2; // default x to center-screen
y = (System.ViewportHeight - sprite.Height) / 2; // default y to center-screen
}
Overlay *displayOverlay = Overlay.CreateGraphical(x, y, sprite.Graphic, false); // create our overlay
sprite.Delete(); // delete our temporary sprite
while (!WaitMouseKey(1)) {} // returns 0 if the time has elapsed, 1 if a mouse button or key was pressed
displayOverlay.Remove();
}
function SpriteFont::display(String Txt, int x, int y){
.
.
(creates txt box)
.
.
Overlay *displayOverlay = Overlay.CreateGraphical(x, y, sprite.Graphic, false); // create our overlay
sprite.Delete(); // delete our temporary sprite
while (!WaitMouseKey(1)) {} // returns 0 if the time has elapsed, 1 if a mouse button or key was pressed
displayOverlay.Remove();
}
function iDullAxe_Look(){
FontDk.display("A Fine Axe but it looks a bit dull from all the chopping.");
}
struct SpriteFont {
// Public
import function SetFontSprite(char c, int spr);
import function SetGuiSprite(int Ctr, int spr); //****** My Gui Sprite Setting Function*********
import function FontSpritesFromView(int v, char firstchar, char numsprites=-1);
import function GuiSpritesFromView(int v); //******* My import Gui sprites function*********
import function FontSpritesFromChar(Character *c, char firstchar=-1, char numsprites=-1);
import function SetFontSpriteFromFile(char c, String filename);
import function FontSpritesFromFiles(String fileroot, char firstchar, char numsprites);
import function GetSpriteTextRawWidth(String t);
import function GetSpriteTextRawHeight(String t);
import function TextOnDrawingSurface(
#ifver 3.0
DrawingSurface *ds,
#endif
int x, int y, String t, int transparent=0, int angle=0);
import function TextOnBackground(int x, int y, String t, int transparent=0, int angle=0, bool Dsp=true);
import DynamicSprite *TextOnSprite(String t);
import Overlay *TextOnOverlay(int x, int y, String t, bool transparent=0);
import Overlay *RenderDisplay(int x, int y, String text ); // ******* monkey_05_06's RenderDisplay *******
// [[THANK YOU!!]]
import function display(int x, int y, String txt); // My Display function
int CharSpacing;
int LineSpacing;
// Private
protected import function GetSpriteCharRawWidth(char c);
protected int sn[MAX_CHAR_VALUE];
protected int GuiSpriteNumber[9]; // *********My Gui Sprite holder Array*********
protected int Max_Txt_Pxl_Width; // ****My Maxium width of Desired Gui Text Box **
protected DynamicSprite *ds[MAX_CHAR_VALUE];
};
// ***************** My Gui Sprite Setting Function ************************
function SpriteFont::SetGuiSprite(int Ctr, int spr){
this.GuiSpriteNumber[Ctr]=spr; // Put the Sprite Number in Gui Text Box Ctr
}
// Modified from......
function SpriteFont::SetFontSprite(char c, int spr) {
this.sn[c]=spr;
this.ds[c]=null;
int height=Game.SpriteHeight[spr];
if (height>this.LineSpacing) this.LineSpacing=height; // find tallest char
}
.
.
.
// ************** My import Gui sprites function ***************************
// Adapted from SpriteFont's FontSpritesFromView
function SpriteFont::GuiSpritesFromView(int v){
int i=0;
int loop=0;
int frame=0;
while (i!=8) {
ViewFrame *vf=Game.GetViewFrame(v, loop, frame);
this.SetGuiSprite(i, vf.Graphic);
i++;
frame++;
if (frame >= Game.GetFrameCountForLoop(v, loop)) {
loop++;
frame=0;
}
if (loop >= Game.GetLoopCountForView(v)) {
Display("ERROR: SpriteFont.GuiSpritesFromView: not enough sprites in view");
QuitGame(0);
}
}
}
function SpriteFont::FontSpritesFromView(int v, char firstchar, char numsprites) {
int i=0;
int loop=0;
int frame=0;
while (i!=numsprites) {
ViewFrame *vf=Game.GetViewFrame(v, loop, frame);
this.SetFontSprite(firstchar+i, vf.Graphic);
i++;
frame++;
if (frame >= Game.GetFrameCountForLoop(v, loop)) {
loop++;
frame=0;
}
if (loop >= Game.GetLoopCountForView(v)) {
if (numsprites<0) return; // -1 just reads all sprites in view
else {
Display("ERROR: SpriteFont.FontSpritesFromView: not enough sprites in view: specified %d, actually %d", numsprites, i);
QuitGame(0);
}
}
}
}
.
.
.
// ***************************** monkey_05_06's RenderDisplay **************************************
// It draws a nice box and boarder around the custom text, but that box and text are still stuck to the screen :(
// Can anyone show me or mokey can you modify so this disapears like a regular Display() function?
Overlay *SpriteFont::RenderDisplay(int x, int y, String text) {
if ((text == null) || (text == "")) return null; // invalid text parameter, abort
int width = this.GetSpriteTextRawWidth(text) + this.LineSpacing + 4; // create the box big enough to fit the text, with 1/2 line-spacing padding, and a 2 pixel black border
int height = this.GetSpriteTextRawHeight(text) + this.LineSpacing + 4;
DynamicSprite *sprite = DynamicSprite.Create(width, height); // the sprite we will render our textbox onto
DynamicSprite *textSprite = this.TextOnSprite(text); // here we grab the sprite-text into a sprite so we can draw it into our textbox
DrawingSurface *surface = sprite.GetDrawingSurface(); // finally open up the sprite to begin drawing
surface.DrawingColor = 31; // white for the background
surface.DrawRectangle(0, 0, sprite.Width, sprite.Height); // fill the entire sprite with white, everything else will go on top
surface.DrawingColor = 0; // black for the border
surface.DrawLine(0, 0, 0, sprite.Height, 2); // draw the border at 2px wide
surface.DrawLine(0, 0, sprite.Width, 0, 2);
surface.DrawLine(sprite.Width, 0, sprite.Width, sprite.Height, 2);
surface.DrawLine(0, sprite.Height, sprite.Width, sprite.Height, 2);
surface.DrawImage(2 + (this.LineSpacing / 2), 2 + (this.LineSpacing / 2), textSprite.Graphic); // draw our text
surface.Release(); // release the sprite so we can create the overlay
textSprite.Delete(); // delete this sprite, we don't need it any more
if (x == -1) x = (System.ViewportWidth - sprite.Width) / 2; // default x to center-screen
if (y == -1) y = (System.ViewportHeight - sprite.Height) / 2; // default y to center-screen
if (x < 0) x = 0; // if the x value is negative, set it back to 0
if (y < 0) y = 0; // same for y value
Overlay *displayOverlay = Overlay.CreateGraphical(x, y, sprite.Graphic, false); // create our overlay
sprite.Delete(); // delete our temporary sprite
return displayOverlay; // return the overlay so we can use it (move it around, remove it, etc.) (also if we don't it will be deleted! ;))
}
.
.
.
.
// ****************** My New attempt at a Text box Gui with custom Sprite Gui Text Tiles *************************
function SpriteFont::display(int x, int y, String Txt){
int GuiBoxlength=0;
int GuiBoxheight=0;
int MiddleLoop=0; // int for how many Top Middle tiles there are?
this.Max_Txt_Pxl_Width=600; // Set Max text Length wanted. This will be setted by a function in the future
if ((Txt == null) || (Txt == "")) return; // invalid text parameter, abort
if ((x == 0) && (y == 0)){ // Set Default if no Parm is passed
x=127;
y=121;
}
int Txtwidth = this.GetSpriteTextRawWidth(Txt); // Get how long the text Graphics will be.
int Lines = (Txtwidth / this.Max_Txt_Pxl_Width); // Find out how many lines will be in the Txt Box
if (Lines == 0){ // if there is only 1 line. Get Box Length and height for sprite.
// Get Sprite With of Top Left Gui Sprite
int TopM=Game.SpriteWidth[this.GuiSpriteNumber[1]]; // Get Width of Top Middle custom Tile
while(GuiBoxlength<Txtwidth){ // Get full Width of the Box's top middle
GuiBoxlength+=TopM;
MiddleLoop++; // adding how many top middle sprites there are
}
GuiBoxlength+=Game.SpriteWidth[this.GuiSpriteNumber[0]] * 2; // Add the length of the two Corner end pieces of the top part of the box for Full Width of the Gui Text Box
GuiBoxheight=(Game.SpriteHeight[this.GuiSpriteNumber[0]] * 2) + (Game.SpriteHeight[this.GuiSpriteNumber[3]]);// Get height by X2 top corner pieces and middle graphic for Full Height of Gui Text Box
}
else{
int TopM=Game.SpriteWidth[this.GuiSpriteNumber[1]]; // Get Width of Top Middle custom Tile
while(GuiBoxlength<this.Max_Txt_Pxl_Width){ // Get how many Top Middle Tiles there are. This has to be done due to the fact
// that custom Gui tile sizes are difrent lengths
GuiBoxlength=GuiBoxlength + TopM;
MiddleLoop++; // adding how many top middle sprites there are to match Max_Txt_Pxl_Width
}
GuiBoxlength+=(Game.SpriteWidth[this.GuiSpriteNumber[0]] * 2); // Add the length of the two end pieces of the top part of the box
GuiBoxheight=(Game.SpriteHeight[this.GuiSpriteNumber[0]] * 2) + (Game.SpriteHeight[this.GuiSpriteNumber[3]] * Lines);// Get height by X2 edge pieces pluss height of side middle tile X how many lines their are
}
//DynamicSprite *clr=DynamicSprite.CreateFromBackground(GetBackgroundFrame(), x, y, GuiBoxlength, GuiBoxheight); //create the erase image
DynamicSprite *sprite=DynamicSprite.Create(GuiBoxlength, GuiBoxheight); // create a sprite as big as the text box needs to be.
DrawingSurface *TxtBox=sprite.GetDrawingSurface(); // Make a drawing surface to Draw the tiles on too
// Draw The Txt box
int spriteX=x; //create another x and y that we can manipulate to draw onto our txt box
int spriteY=y;
TxtBox.DrawImage(spriteX, spriteY, this.GuiSpriteNumber[0]); // Draw Top Left Tile Onto the sprite
spriteX+=Game.SpriteWidth[this.GuiSpriteNumber[0]]; // advance spriteX forward
while(MiddleLoop>0){ //Put the Top Middle Tiles in
TxtBox.DrawImage(spriteX, spriteY, this.GuiSpriteNumber[1]);
spriteX+=Game.SpriteWidth[this.GuiSpriteNumber[1]];
MiddleLoop--;
}
TxtBox.DrawImage(spriteX, spriteY, this.GuiSpriteNumber[2]); // Draw top Right Tile
// I stopped here to just to see if the top part of the Sprite would be drawn Correctly
TxtBox.Release(); // Update Memory
Overlay *displayOverlay = Overlay.CreateGraphical(x, y, sprite.Graphic, false); // create our overlay
sprite.Delete(); // delete our temporary sprite
//return displayOverlay; // return the overlay so we can use it (move it around, remove it, etc.) (also if we don't it will be deleted! ;))
Wait(400);
//clear.Release();
displayOverlay.Remove();
}
By continuing to use this site you agree to the use of cookies. Please visit this page to see exactly how we use these.
Page created in 0.186 seconds with 14 queries.