Question

i am developing a 2D game using Andengine this engine works great. The problem i am facing right now is i m using the Text class of engine to show the score at screen and when i update the text it is causing the lag. Can any one tell me whats the problem? here is the code where i am updating text.

        final ITexture scoreFontTexture = new BitmapTextureAtlas(this.getTextureManager(),256,256);
    mScoreFont = FontFactory.createFromAsset(this.getFontManager(),scoreFontTexture,this.getAssets(),"african.ttf",20f,true,Color.WHITE);
    mScoreFont.load();
    scoreText = new Text(340, 10, this.mScoreFont, "Score \n 0","00000000000".length(), getVertexBufferObjectManager());
    myScene.attachChild(scoreText);
    final TimerHandler handler=new TimerHandler(1.3f,true ,new ITimerCallback() {   

        @Override
        public void onTimePassed(TimerHandler pTimerHandler) {

            mPlayerScore++;
             scoreText.setText(mPlayerScore+"");
        }
    }); 
    myScene.registerUpdateHandler(handler);
Was it helpful?

Solution

I also experienced this problem. It seems that AndEngine loads a number from the Font only when it needs the number, which causes the lag, since the loading time is slow.

Initialising scoreText with a value of "Score \n 0123456789" resolved the issue for me, it forces AndEngine to load all the numbers needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top