Heyho
I have a little prototype game with box2d physics activated. in my game there is a player that shoots bullets where every bullet has a “dynamic” physics body to detect collision with other objects. in a later stage of my game there will probably be a lot of bullets flying around on the screen. now there are two implementations I thought about:
local BulletClass = {} function BulletClass.new(stage, xPos, yPos) local bullet = display.newCircle(xPos, yPos, 5) stage:insert(bullet) physics.addBody( bullet, "dynamic", {density=1, friction=0, bounce=0, radius = 5 } ) bullet.isBullet = true camera:add(bullet, 2) bullet.speedPerSecond = 400 bullet.distance = 200 bullet.name = "bullet" function bullet.shoot(toXPos, toYPos, withPhysics) if withPhysics then local vector = utils.getDirection(toXPos - xPos, toYPos - yPos, 1) bullet:applyLinearImpulse(vector.x\*1, vector.y\*1, xPos, yPos) timer.performWithDelay( 2000, function() display.remove(bullet) end, 1) else local vector = utils.getDirection(toXPos - xPos, toYPos - yPos, bullet.distance) local travelTime = (bullet.distance / bullet.speedPerSecond) \* 1000 transition.moveBy( bullet, { time = travelTime, x = vector.x, y = vector.y, onComplete = function() display.remove(bullet) end} ) end end return bullet end return BulletClass
the important part is inside the shoot function where I can switch between a physics version and a transition version. I would like to use the physics version because it is easier to implement bouncing bullets or things like that in the future. but with a lot of bullets on the screen I am afraid that I will see huge fps drops due to a lot more calculations compared to the transition.to version of my bullet. how much more does the applyLinearImpulse version cost me?
grettings
gritob