Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a labelSwitch do something when I turn it on and off?
    text
    copied!<p>When I press my switch so that it shows the "on" position, how do I actually make it do something, for example, link it to a method that sets the volume of a player to 0? I'm guessing its Interface <code>FieldChangeListener</code>?</p> <p>All my implementation occurs in the <code>MainScreen</code> class.</p> <pre><code>Bitmap switch_left = Bitmap.getBitmapResource("switch_left.png"); Bitmap switch_right = Bitmap.getBitmapResource("switch_right.png"); Bitmap switch_left_focus = Bitmap.getBitmapResource("switch_left_focus.png"); Bitmap switch_right_focus = Bitmap.getBitmapResource("switch_right_focus.png"); LabeledSwitch silentSwitch = new LabeledSwitch(switch_left, switch_right, switch_left_focus, switch_right_focus, "on", "off", true ); JustifiedHorizontalFieldManager silent = new JustifiedHorizontalFieldManager( new LabelField( "Silent Mode" ), silentSwitch, false, USE_ALL_WIDTH ); silent.setPadding(5,5,5,5); add(silent); </code></pre> <p>I imported a game demo called OpenGlSpriteDemo, and looked at how they implemetned the start button with field change listener, so I tried to do that for the Labeledswitch. Am I heading in the right direction?</p> <pre><code>LabeledSwitch silentSwitch = new LabeledSwitch(switch_left, switch_right, switch_left_focus, switch_right_focus, "on", "off", false ); silentSwitch.setChangeListener(this); public void fieldChanged(Field arg0, int arg1) { //If user sets the switch to on, reduce the volume to 0, // else if user sets the switch to false, change it back // to the default volume } </code></pre> <p><img src="https://i.stack.imgur.com/gNnwm.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload