Not sure if this should be posted in the newbie section… But I am a newbie… So… Yeah
Anyway, I’m currently running into a peculiar problem. I’m working on an Angry Bird-esque game, where the user fires a bomb at buildings, the “camera” follows the bomb as it flies and zooms out as it travels.
I’m currently working on a reset function, that respawns the bomb after you fired it, but I noticed that my game.height is increasing infinitely! I’m using print(game.height) and notice that its at 660 at the start (which I find to be a weird number, but okay it works fine), but after I fire once it just increases and increases and increases.
This is my code for handling my “camera” (I call it a camera, but all I’m doing is move image groups across the board).
--Main loop function loop(e) if hit == false then local targetx = (- bomb.x + 100) \* game.xScale local targety = (- bomb.y) \* game.yScale if targetx\>0 then targetx = 0 elseif targetx\<-400 then targetx = -400 end game.xScale = 1 + (game.x\*0.0008) game.yScale = game.xScale game.x = game.x + (targetx-game.x)\*0.25 game.y = (game.height - (game.height \* game.yScale))/2 print("game height", game.height) print("---") elseif hit == true then end end
This loop is run every frame, since it needs to calculate where the camera has to be at every frame. I dont think any other code needs to be posted, since none of the other code touches attributes from the game group.
To clarify, “hit” is to determine whether the bomb hit something or not, thus freezing the camera in place for a few seconds, before a new bomb is spawned and hit is set back to false.