Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: anarchist on May 19, 2012, 11:37:30 PM

Title: Help with tiled images
Post by: anarchist on May 19, 2012, 11:37:30 PM
Hello everyone,

I have just started working with tiled images in a window and have met some trouble.

I have a window of dimensions 150x150 which contains a static control of the exact same dimensions. I have created a .image file and have assigned it as the TiledImage of the static control (I have also tried assigning it to the window after I met trouble). The .image file looks like the following:

Code: WME Script
  1. TILED_IMAGE
  2. {
  3.   IMAGE="interface\window\windowBackground.png"
  4.   VERTICAL_TILES { 50, 50, 50 }
  5.   HORIZONTAL_TILES { 50, 50, 50 }
  6. }
  7.  

windowBackground.png is an image of dimensions 150x150 filled with a monochrome colour.

I want this to appear next to the actor and be filled with text. I want it to have fixed length and variable height to adjust to the amount of text. The code I use to show this window is the following (by calling Object.comment(text)).

Code: WME Script
  1. var textBox = commentWindow.GetControl("commentText");
  2.  
  3. method initialize(){
  4.         var height;
  5.         var width;
  6.        
  7.         //place the window
  8.         commentWindow.Height = textBox.Height;
  9.        
  10.         if(actor.X + commentWindow.Width + 10 > Game.ScreenWidth) commentWindow.X = Game.ScreenWidth - width;
  11.         else commentWindow.X = actor.X + 10;
  12.        
  13.         if(actor.Y + commentWindow.Height > Game.ScreenHeight) commentWindow.Y = Game.ScreenHeight - height;
  14.         else commentWindow.Y = actor.Y - actor.Height;
  15. }
  16.  
  17. ////////////////////////////////////////////////////////////////////////////////
  18. method comment(commentText)
  19. {
  20.         textBox.Text = commentText;
  21.         textBox.HeightToFit();
  22.        
  23.         this.initialize();
  24.         this.Visible = true;
  25. }
  26.  

The window successfully adjusts its height on the amount of text the static control contains. Unfortunately, the tiled image seems to not behave correctly. Sometimes it fills the window correctly but sometimes it is cut short at the bottom:

(http://img28.imageshack.us/img28/5775/screenshotvtp.png)

What causes such behaviour? Am I missing something regarding tiled images?

Thank you
Title: Re: Help with tiled images
Post by: Mnemonic on May 20, 2012, 07:29:59 AM
You need to make sure the height is rounded to the nearest higher multiple of 50. Something like this:

Code: WME Script
  1. textBox.HeightToFit();
  2. if (textBox.Height % 50 > 0) textBox.Height = textBox.Height + (50 - (textBox.Height % 50));
  3.  
Title: Re: Help with tiled images
Post by: anarchist on May 20, 2012, 01:12:46 PM
Thank you Mnemonic! Works like a charm  :) So if I get it right, the static control was empty at the bottom because the tile needs a space of 50pixels to fill?

Also is this
Code: WME Script
  1. commentWindow.Height = textBox.Height;
necessary?
Title: Re: Help with tiled images
Post by: Mnemonic on May 20, 2012, 07:50:15 PM
Depends. If you don't resize the window, your label will be partially outside the window bounds. If the window's ClipChildren property is set to true, the outside part will be cut.
Title: Re: Help with tiled images
Post by: anarchist on May 21, 2012, 04:48:03 PM
Thanks again mnemonic you have been very helpful  ::thumbup