How to change button image background

Monkey Targets Forums/iOS/How to change button image background

soXes(Posted 2013) [#1]
Hi All,

Do you know how to change image background of a button. i would like to switch button to 2 state ON/OFF of sound button.

I am using CreateImage to create image button.

Any advice!


MikeHart(Posted 2013) [#2]
The best thing is to create an object that holds the two images. Then it needs a state field. Once you determine a click on it, change the state accordingly. Then draw one of the images depending on the state.


MikeHart(Posted 2013) [#3]
In general, Your question is not Ios specific, but rather in the general Monkey programming area. Rather post there if you need general coding/design answers.

It also helps to post some code you have done yourself, so people can make suggestions about your code.


soXes(Posted 2013) [#4]
thanks for your replying soon.

My code is blow:

Local sound:ftObject = eng.CreateImage(fileName, px, py)
sound.SetTag(SOUND_BUTTON_TAG)
sound.SetTouchMode(2)
sound.SetLayer(bgLayer)
sound.SetScale(0.8)

I would like to change sound object to other state (ON/OFF), i know when we click on this button, i can create other image for this object by calling CreateImage method too. But there are any way easier and not call CreateImage, i am afraid it will increase memory when we draw too much image on screen. method could be SetImage, Update Image ...?


MikeHart(Posted 2013) [#5]
Which version of fantomEngine do you use?


soXes(Posted 2013) [#6]
It is version 152


MikeHart(Posted 2013) [#7]
A current way you could do is to put both images into a strip and then use eng.CreateAnimImage. Then handle the animation manually, by pausing the animation with SetAnimPaused and set the frame you want to display with SetAnimFrame.

I am in the process of adding the ability to add seperate images to an existing image object, so there it will be even more easier to setup an animated object.


soXes(Posted 2013) [#8]
yes, thanks.

That seems good solution now.