Flip image, flip button?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Flip image, flip button?

Post by MarkoSato » Sat May 21, 2016 5:41 pm

Hello,

I have a code where with a random chance of 50 % an image flips
"if random(1000)<500 then flip image who horizontal"
I want to do the same with a button(which has an image on it).
Is it possible? Because with the same code it said error.

Best regards
Mark

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Flip image, flip button?

Post by bn » Sat May 21, 2016 6:40 pm

Hi Mark,

the icon of a button is only refreshed when you click the button.

To do what you want set the icon of the button to the id of the image you just flipped.

Like this

Code: Select all

on mouseUp
   lock screen
   put random(1000) into tNumber
   if tNumber < 500 then 
      flip image "myImage" horizontal
      set the icon of button 1 to the id of image "myImage"
   end if
   unlock screen
end mouseUp
Kind regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Flip image, flip button?

Post by bn » Sat May 21, 2016 6:49 pm

you could also script

Code: Select all

 set the icon of button 1 to the icon of button 1
instead of the "id of image "myImage""

Kind regards
Bernd

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: Flip image, flip button?

Post by MarkoSato » Sun May 22, 2016 5:30 pm

Hello,

This doesn't work like I want it to be (or I couldn't do it right).
I have a start button which spawns 1-10 random enemies. These enemies were images before so I had no problem flipping them.
When I clicked the start button, some of the enemies faced the right side and some the left side.
Now I changed the enemies to a button with the same image, but when you hover or click the button('enemy') the image changes[So it has a little effect].
Now I want to flip those random enemies but with that code you wrote, it flipped all the same, so either everyone got flipped, or none.
But I wanted it to be random so for example 3 are looking right, 4 are looking left.

Hope I could explain it well

Best regards
Mark

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Flip image, flip button?

Post by Klaus » Sun May 22, 2016 6:41 pm

Hi Mark,

since icons in buttons with identical IDs always display the SAME image (no instance or whatever!)
and if you modify (flip in your case) that image, the cahnge will be reflected in all buttons that have
this images as icon!

Simply make a copy of your image and flip that one so you can use this as the "flipped" icon while
preserving the "original" unflipped image! :D


Best

Klaus

MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: Flip image, flip button?

Post by MarkoSato » Sun May 22, 2016 10:24 pm

Hey,

thanks for the help! I got it to work now :D

Best regards,

Mark

Post Reply