1

I am making a racing game looking like old school "Pole position" (kind of).

I create my road from 50 rectangles (RoadFragment is a rectangle with two additional white small rectangles attached to simulate curbs of the road):

   int y = 0;
    int widthCut = 8; // 4 przy 100 prostokatach, 8 przy 50
    for(int rectIndex = 0; rectIndex < rectangleCount; rectIndex++)
    {
        RoadFragment roadFragment = new RoadFragment(400, 0, 500, 300 / rectangleCount, RaceScene.vbom);
        roadFragments.add(rectIndex, roadFragment);
        this.attachChild(roadFragments.get(rectIndex));
        roadFragments.get(rectIndex).setY(rectIndex * 6);
        roadFragments.get(rectIndex).setWidth(500 - y);

        y = y + widthCut;

    }   

in onManagedUpdate of the scene I move those fragments:

    timeToUpdate = timeToUpdate + pSecondsElapsed;
    if(timeToUpdate > 0.00f){
        timeToUpdate = 0;

        for(int rectangleIndex = 0; rectangleIndex < rectangleCount; rectangleIndex++) {

            roadFragments.get(rectangleIndex).setX(getBezierX((float)rectangleIndex, (float)rectangleCount, 400, 400, 400 + curveOffset));

        }

    }

As you can see there on every update there is a calculation made for every of these fragments to move them by a factor calulated from bezier curve. There ar also some other sprites on the scene: parallax background, player's car, some other cars (but not more than two at the same time, and few other. In total I have 150 rectangles drawn and about 10 sprites.

So, on Galaxy S5 it looks really nice and smooth, but on bit older phones like Galaxy S3 mini it stutters and is unplayable. Question is: is there any trick, change or idea I could use to make it smoother?

Łukasz Motyczka
  • 1,169
  • 2
  • 13
  • 35

1 Answers1

0

May be the problem in the part of code where you render these rectangles? You need to batch the sprites.

http://www.andengine.org/forums/updates/spritebatch-2x-performance-improvement-anyone-t3613.html

user1136881
  • 182
  • 1
  • 6