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\$
  • \$\begingroup\$ This should work. Unless you set current tile index to 0 again somewhere else. \$\endgroup\$ – sm4 Aug 26 '13 at 4:07
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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.