Lots of Lag/stuttering - is it cause of Box2d? I only have about 70 physics bodies

I am having issues with my game. It is not a complicated game so there shouldn’t be this kinda lag. I used to develop flash games, and have experienced box2D lag there, and had to work with it, even though I was only creating like 40 physics bodies.

In this game, I have about 70 physics bodies on the screen at one time. Once they are off of the screen, I remove them, make them nil, and create others to replace them. These bodies are just blocks. Imagine super mario blocks/tiles. Nothing happens to them, they are just used for collision. If collided with, the character dies.

Why is it so choppy? I am hardly doing anything but moving them from right to left at a fast pace.

*My current FPS in build settings is set to 60

*70 physics objects on screen, all the same size, no explosions, no particles

*I remove physics bodies when they go off screen, or when the game is reset

*I create physics bodies when the old bodies go off screen, or when the game is reset

Nothing crazy happening here. Is 70 too much for a phone? There shouldn’t be lag, especially using my Samsung Galaxy 4 and my Verizon LG G2 (top of line, state of the art)

Any help please :smiley:

You might want to throw in a memory monitoring module, just to see what, if anything, is eating up your performance. If you’ve got 70 physics bodies, each with their own collision listener, and a bunch of other Runtime listeners all going at the same time, with print statements, it can get somewhat laggy.

Shameless plug: Lerg’s performance monitor

These are my listeners:

startGamePic:addEventListener(“touch”, startGame) – just a touch, nothing to do with physics

Runtime:addEventListener( “enterFrame”, move ) – This is my MAIN LOOP, Moves all objects including physic bodies

player:addEventListener( “preCollision” ) – if player collides with physics bodies

player.collision = charCollide – if player collides with  physics bodies

player:addEventListener( “collision”, player ) – if player collides with  physics bodies

Nothing else really going on. Just checking to see if the player collides (and pre-collision) with physics bodies

You might want to throw in a memory monitoring module, just to see what, if anything, is eating up your performance. If you’ve got 70 physics bodies, each with their own collision listener, and a bunch of other Runtime listeners all going at the same time, with print statements, it can get somewhat laggy.

Shameless plug: Lerg’s performance monitor

These are my listeners:

startGamePic:addEventListener(“touch”, startGame) – just a touch, nothing to do with physics

Runtime:addEventListener( “enterFrame”, move ) – This is my MAIN LOOP, Moves all objects including physic bodies

player:addEventListener( “preCollision” ) – if player collides with physics bodies

player.collision = charCollide – if player collides with  physics bodies

player:addEventListener( “collision”, player ) – if player collides with  physics bodies

Nothing else really going on. Just checking to see if the player collides (and pre-collision) with physics bodies