Page 1 of 1

Using create image and templateImage...

Posted: Tue Apr 16, 2013 12:34 am
by PaulMaguire
Hi.

I am new to Livecode - bear with me please.

I am trying to implement the create image function, using the tempateImage object. I almost have it. I'm creating lots of images on the fly I create an image and set the PNG filename to it and resize it to fit (for retina). It works fine first time then when I return to the same card the scale is wrong (it's too big). Here is my code:

Code: Select all

on setUpMapIcons   
   if the environment is "mobile" then
      put specialFolderPath("Engine")&slash&"Media/MapIcons"&slash into tP
   else
      put specialFolderPath("Desktop")&slash&"MapIcons"&slash into tP
   end if
   lock screen for visual effect
   put 0 into tC
   set the width of the templateImage to 64 -- these 2 lines have no effect - why?
   set the height of the templateImage to 64
   lock messages
   repeat for each line tMkey in the keys of gSlugList -- gSlugList is a list of filename without .png suffix
      put gSlugList[tMkey] into tA
      repeat for each line tS in the keys of tA
         -- Name
         add 1 to tC
         put ("mapIcon"&tC) into i
         -- create image
         set the resizeQuality of the templateImage to "good"
         create invisible image i in group "G_MapButs"
         -- Filename for icon
         set the filename of image i to (tP&"MapIcon_"&tA[tS]&".png")
         set the width of image i  to 64 -- original PNG size is 128x128 - this works first time then has no effect on revisting this card!!!
         set the height of image i to 64 -- neither does this...
          setImageLoc -- positions image on map
          show image i
     end repeat
   end repeat
   unlock messages
   unlock screen with visual effect dissolve very fast
end setUpMapIcons
Do I need to delete/destroy the images when I leave the card? No idea why the images don't respond to setting the scale. Also don't understand why setting the templateImage properties has no effect. Any help appreciated. Thanks.

Kind regards, Paul.

Re: Using create image and templateImage...

Posted: Tue Apr 16, 2013 12:51 am
by PaulMaguire
Got it. I need to delete all dynamically-created images on closeCard. Excellent.

Kind regards, Paul.

Re: Using create image and templateImage...

Posted: Tue Apr 16, 2013 8:58 am
by jmburnod
Hi paul,
I need to delete all dynamically-created images on closeCard
To keep the size of the img

Code: Select all

set the lockLocation of img i to true
is your friend
Best regards
Jean-Marc

Re: Using create image and templateImage...

Posted: Tue Apr 16, 2013 10:00 am
by PaulMaguire
Ah - bien sûr! Merci beaucoup Jean-Marc.

Kind regards, Paul.