4
\$\begingroup\$

I want to change width of sprite dynamically but i can't perform it.!! Here i want to change only my white sprite i want to use these type of facility in my game in using AndEngine I want to display life of player

enter image description here

\$\endgroup\$
5
\$\begingroup\$

I add my code its for temporary code you can change this code set your life of player

    life = 10;
    final Sprite whiteSprite= new Sprite(0, 0, testRegion);
    scene.attachChild(whiteSprite);
    width = whiteSprite.getWidth();
    scale = width/life;

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            width-=scale;
            if (width > 0) {
                whiteSprite.setWidth(width);
            }
        }
    }, 5000, 1000);
\$\endgroup\$
0
0
\$\begingroup\$

I finally found how you can change width or height with modifiers of andengine. Don't think you need it now. But it can be helpful for others.

entity.registerEntityModifier(new SingleValueSpanEntityModifier(duration, fromHeight, toHeight) {
        protected void onSetInitialValue(IEntity pItem, float pValue) {}
        @Override
        protected void onSetValue(IEntity pItem, float pPercentageDone, float pValue) {
            ((CLASS)pItem).setHeight(pValue);
            //where CLASS is the class of your item (Rectangle or Sprite...)
            //as Entity class hasn't width and hight params.
            // pValue is a variable from modifier. So, you write it like that.
        }
        public IEntityModifier deepCopy() throws DeepCopyNotSupportedException {return null;}
    });
\$\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.