Page 1 of 1
Flip image, flip button?
Posted: Sat May 21, 2016 5:41 pm
by MarkoSato
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
Re: Flip image, flip button?
Posted: Sat May 21, 2016 6:40 pm
by bn
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
Re: Flip image, flip button?
Posted: Sat May 21, 2016 6:49 pm
by bn
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
Re: Flip image, flip button?
Posted: Sun May 22, 2016 5:30 pm
by MarkoSato
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
Re: Flip image, flip button?
Posted: Sun May 22, 2016 6:41 pm
by Klaus
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!
Best
Klaus
Re: Flip image, flip button?
Posted: Sun May 22, 2016 10:24 pm
by MarkoSato
Hey,
thanks for the help! I got it to work now
Best regards,
Mark