1

I need an easy code for a push button that makes an image 2 times smaller with each click in livecode the image is 300 width 300 height

Ayla
  • 29
  • 6
  • 1
    Could you please show example with your code – Alex Vovchuk Jan 21 '20 at 20:37
  • when i click on a push button i want an image to be 2 times smaller each time , sorry I can't give any examples because I have just started learning livecode and I am new to it – Ayla Jan 21 '20 at 20:41
  • on UpdateScore if field "score" > 0 then subtract 1 from field "score" remove 2 of width of image "clickMe" remove 2 of height of image "clickMe" save this stack – Ayla Jan 21 '20 at 22:01
  • Don't you need a limit, to make sure that the image doesn't get too small to click on? – Mark Jan 22 '20 at 10:41

3 Answers3

1

Lets say the name of your image is myImage

set the width of image "myImage" to the width of image "myImage" /2
set the height of image "myImage" to the height of image "myImage" /2
Matthias Rebbe
  • 116
  • 1
  • 7
1

Here is one way you could do it. Create a custom command handler in your card or stack script:

command resizeImage pImgName, pResizeFactor
  set the resizeQuality of image pImgName to "good"
  set the width of image pImgName to the width of image pImgName * pResizeFactor
  set the height of image pImgName to the height of image pImgName * pResizeFactor
end resizeImage

In a button, or even in the image object script, write a mouseUp handler:

on mouseUp
  resizeImage "imageNameHere", .5
end mouseUp

Of course you would put the actual name of the image in place of "imageNameHere".

Devin
  • 593
  • 1
  • 3
  • 8
1

I've checked out the older anwers and I think they forget to make sure that the image stays in the same location. I'm also adding a lock screen command. You may omit this if you think it slows down the button too much.

You can put the mouseUp handler into script of the button and the resizeImage handler anywhere higher up the message hierarchy or in the script of the button itself.

on mouseUp
  lock screen
  resizeImage the long id of img 1
  unlock screen
end mouseUp

on resizeImage theImg
  put the loc of theImg into myLoc
  set the width of theImg to the width of theImg / 2
  set the height of theImg to the height of theImg / 2
  set the loc of theImg to myLoc
end resizeName

You need to adjust the long id of img 1 to make sure it changed the size of the correct image, for instance use the long id of img id 69456 if the short id is 69456 or the long id of img "my image" if the name of the image is "my image".

Mark
  • 2,380
  • 11
  • 29
  • 49