Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Help with tiled images  (Read 4075 times)

0 Members and 1 Guest are viewing this topic.

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Help with tiled images
« 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:



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

Thank you
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Help with tiled images
« Reply #1 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.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Help with tiled images
« Reply #2 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?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Help with tiled images
« Reply #3 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.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Help with tiled images
« Reply #4 on: May 21, 2012, 04:48:03 PM »

Thanks again mnemonic you have been very helpful  ::thumbup
Logged
 

Page created in 0.027 seconds with 21 queries.