Using create image and templateImage...

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Contact:

Using create image and templateImage...

Post by PaulMaguire » Tue Apr 16, 2013 12:34 am

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.

PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Contact:

Re: Using create image and templateImage...

Post by PaulMaguire » Tue Apr 16, 2013 12:51 am

Got it. I need to delete all dynamically-created images on closeCard. Excellent.

Kind regards, Paul.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Using create image and templateImage...

Post by jmburnod » Tue Apr 16, 2013 8:58 am

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
https://alternatic.ch

PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Contact:

Re: Using create image and templateImage...

Post by PaulMaguire » Tue Apr 16, 2013 10:00 am

Ah - bien sûr! Merci beaucoup Jean-Marc.

Kind regards, Paul.

Post Reply