Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: NsMn on Sun 22/11/2009 17:52:54

Title: Code or function - Sprite not drawn on DrawingSurface
Post by: NsMn on Sun 22/11/2009 17:52:54
Hello all,

I'm back with a weird question and a mile-long code for you to debug ._.

Whatever, for my text game, I coded this little function, which should append text on the screen and set the parser position under it.


function AddText(const string Text, int Colour){
  //180
  //280
  String NewStorytext=Storytext.Append(String.Format("[%s",Text));
  String Newtext=Text;
  int Textheight=GetTextHeight(Newtext.Copy(), eFontFont0, 280);
  int Charheight=GetTextHeight("2xXcgV2§", eFontFont0, 280);
 
  TextSprite=DynamicSprite.CreateFromExistingSprite(btnText.NormalGraphic, true);
  DynamicSprite*TextSpriteBuffer=DynamicSprite.CreateFromExistingSprite(btnText.NormalGraphic, true);
  if(GetTextHeight(NewStorytext, eFontFont0, 280)+btnText.Y > 197){
  while(GetTextHeight(NewStorytext, eFontFont0, 280)+btnText.Y > 197){
    //Display("%d",GetTextHeight(NewStorytext, eFontFont0, 280));
    //NewStorytext=NewStorytext.Substring(0, 280/GetTextWidth("2",eFontFont0));
    TextSprite.ChangeCanvasSize(TextSprite.Width, TextSprite.Height+Charheight, 0, 0);
    btnText.Y=btnText.Y-Charheight;
  }
  }
  TextSurface=TextSprite.GetDrawingSurface();
  TextSurface.DrawingColor=Colour;
  TextSurface.DrawStringWrapped(0, GetTextHeight(Storytext, eFontFont0, 280), 280, eFontFont0, eAlignLeft, Text);
  Storytext=Storytext.Append(String.Format("%s",Text));
  lblSave.Y=GetTextHeight(Storytext.Copy(), eFontFont0, 280)+btnText.Y;
  if(lblSave.Y > btnText.Y+180)lblSave.Y=btnText.Y+180;
  btnArrow.Y=lblSave.Y+4;
  TextSurface.Release();
  btnText.NormalGraphic=TextSprite.Graphic;
}


It's a very long script, but the problem is only somewhere in that while loop, which should check whether the text is igger than the screen and if yes, should cut off the upper part. But, it doesn't work; If it is longer, it just clears the screen and puts the text window (label actually) somewhere under the screen's lower edge.