Object casting using "enterFrame" instead of timer.performWithDelay

Hello, this topic is conected from [this].(Timer still iterate even when it crash. - #3 by morethanamotion) I’m happy to share to you that I unexpectedly discover how to simultaneously cast object using an “enterFrame” listener as replacement for timer.performWithDelay()

Using the “enterFrame” Runtime Event listener, I calculate the event.frame’s %(modulo) to 100 under the local base variable, and every time that base is equal to 0, a rectangle is casted:

	local castBullet
	local bullet


	local function Berserk( event )
		local goframe = event.frame
		local base = goframe % 100 ---> change this value to have faster iteration. istead of 100, try lower or higher. But I sugest, it is much better if it is divisible by 5 (:

		if ( base == 0 ) then
			bullet = display.newRect(display.contentCenterX, display.contentCenterY, 100, 50)
			bullet.rotation = math.random(0, 360)

		end
		local rotationInRadians = bullet.rotation*math.pi/180
		local movementPerFrame = 3
		local xMovement = math.cos(rotationInRadians)*movementPerFrame
		local yMovement = math.sin(rotationInRadians)*movementPerFrame

		bullet.x = bullet.x + xMovement
		bullet.y = bullet.y + yMovement
	end

	Runtime:addEventListener("enterFrame", Berserk)

Now, even you hold down the minimize or close(x) button of the simulator, it will pause but it will still continue from the time it paused when you released.

I hope that it helped you, You’re welcome in advance. I will be very happy for all opinions, suggestions, advice and more. Thank you very much