hello everyone i need some help adding a timer to all the shells as they exit the gun so that they will decay after a few seconds so they do not clutter the ground.
--- Start of function if playerInfo.fireing == "true" then FireingTick = FireingTick +1 for a = 1,1,1 do local shells = display.newImage("Guns/shell.png") shells.name = FireingTick if onFloorA == "true" then shells.x = spawnX shells.y = spawnY end if onFloorB == "true" then shells.x = spawnX shells.y = animation.y end playerShells:insert(shells) physics.addBody( shells, "dynamic", { density=3.0,friction=1.0, bounce = .2 } ) if playerInfo.direction == "r" then shells:applyLinearImpulse( -.1, -.2, shells.x, shells.y ) shells:applyTorque(10) end if playerInfo.direction == "l" then shells:applyLinearImpulse( .1, -.2, shells.x, shells.y ) shells:applyTorque(10) end end end -- call function with deley of 255. this gives me 5 shells per second
so can anyone help me add a timer to “shells” then somehow while they are alive they need to start counting down then go away. ??? im baffled by this at the moment.
i have “FireingTick” counting the number of shells that have been ejected but i dont understand how i can add a timer to each shell then start that timer for each shell then remove it from the group or whatever. iv tried several ways but i cant seem to get the shells to come off the screen. usually when i typed up a way of doing it i get an error or the new shells that i make will vanish not the old shells on the screen…
thank you guys.