Hi, I am creating a game and I have a conceptual question that I’d like to know.
I am using the composer library to change between scenes
This is part of my code.
local coin local function spawnCoins() local sceneGroup = scene.view coin = display.newImageRect("level1/bitcoin.png",58,59) coin.x = math.random(300,17\*480) coin.y = math.random(y/4,y\*2-20) coin.name = "coin" sceneGroup:insert(coin) coin.enterFrame = scrollSnowBackground Runtime:addEventListener("enterFrame", coin) physics.addBody(coin, "dynamic", {bounce = 0, filter = filtersTable.coinFilter ,friction = 0, isSensor = true, radius = 30}) coin.gravityScale = 0 coin:addEventListener("collision", onCollisionCoin) end
Then, at the beginning of the game I call the function as follows when the scene is shown
for i = 0,8,1 do spawnCoins() end
I didn’t include other functions since I don’t think they are important to my question.
I am creating the object as a local variable to the function spawnCoins() and I am adding event listeners to it.
Do I have to remove the event listener at any point? Like when changing the scene? Or I don’t have to worry about it?
Thanks