@betterwithlasers wrote:
Hi everyone,
I'm currently trying to combine the inbuilt Physics Engine and TileMap classes to create the levels for my physics-based sidescroller. These functionalities work fine seperately and there is no slowdown. However there is major slowdown (down to 15fps for a long time) when I try to combine these two steps, after creating the tilemap I try to place a physics body for each 'filled-in' tile.for (int x=0; x < 80; x++) //width of map { for (int y = 0; y < 24; y++) //height of map { auto spriteTile = wallLayer->getTileAt(Vec2(x,y)); if (spriteTile != NULL) { PhysicsBody* tilePhysics = PhysicsBody::createBox(Size(30.0f, 30.0f), PhysicsMaterial(1.0f, 1.0f, 0.0f)); tilePhysics->setDynamic(false); //static is good enough for walls spriteTile->setPhysicsBody(tilePhysics); } } }
As you can see I am basically bruteforcing it, the map is size 80*24 tiles and each tile is 30*30 pixels big. My main question is is there a better way to assign physics bodies to tiles? Or am I creating some kind of memory leak with the physics bodies? Note: wallLayer is the layer the tiles are on, and most of it is blank, so I don't think tile count is the problem.
Any insight would be helpful, thanks
Posts: 1
Participants: 1