2
\$\begingroup\$

I need to make a button with texture. After button is pressed I want to change texture of button permanently. For example on/of sound button. I tried this but it changes image only while I hold button.

Thanks

mSoundButton  = new ButtonSprite(30, 30,
                    ResourceManager.getSoundButtonTR(),  
 //tiled texture region with image for sound on and sound off
                    ResourceManager.getEngine().getVertexBufferObjectManager()) {
        @Override
        public boolean onAreaTouched(TouchEvent pTouchEvent, 
                                     float pTouchAreaLocalX, 
                                     float pTouchAreaLocalY) {
            if(pTouchEvent.isActionDown()) {
                SFXManager.toggleSoundEnabled();
                this.setCurrentTileIndex(1);
            }
            return super.onAreaTouched(pTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
        }
    };
    mScene.registerTouchArea(mSoundButton);
    mScene.attachChild(mSoundButton);
\$\endgroup\$
1
  • \$\begingroup\$ This should work. Unless you set current tile index to 0 again somewhere else. \$\endgroup\$ Aug 26, 2013 at 4:07

1 Answer 1

2
\$\begingroup\$

this solution works for me:

mSoundButton  = new ButtonSprite(30, 30,
                                     ResourceManager.getSoundButtonTR(),
                                     ResourceManager.getEngine().getVertexBufferObjectManager(),
                                     new ButtonSprite.OnClickListener() {
                @Override
                public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {

                    SFXManager.toggleSoundEnabled();
                    mSoundButton.setCurrentTileIndex(SFXManager.isSoundEnabled() ? 0 : 1);

                }
    });
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .