I now have found a system memory leak and was able to find the part in my code which is causing it.
I don’t see where it is happening and hope someone can give me a hint:
local WeaponX,WeaponY=Weapon:localToContent( 0,0 ) local enemyX,enemyY=lockedOnEnemy:localToContent( 0,0 ) local damage=Weapon.damage local endX,endY=Weapon.laserGoalPoint2:localToContent( 0,0 ) if laseractive==false then laseractive=true local ePosX,ePosY -- THIS IS THE PROBLEM AREA: if \_G.Enemy then for \_, enemyx in pairs( \_G.Enemy ) do if enemyx and enemyx~=nil and enemyx.x and enemyx.x~=nil then ePosX,ePosY=enemyx:localToContent( 0,0 ) --local ePosX=enemyx.x --local ePosY=enemyx.y if Weapon.laser.isVisible==true and enemyx.isAttackable==true and enemyx.isVisible==true then if CircleLineCollDetection (WeaponX,WeaponY,endX,endY,ePosX,ePosY,enemyx.width\*0.5) then -- check for enemy death if Weapon.laser.isVisible==true then -- old pos: checkLaserEnemyHit(enemyx,damage,Weapon) -- checking if smoke is already on: if enemyx and enemyx.isVisible==true and enemyx.hitsmoke and enemyx.hitsmoke.state~="playing" then enemyx.hitsmoke:start() end checkLaserEnemyHit(enemyx,damage,Weapon) else laseractive=false -- checking if smoke is already on: --if enemyx.hitsmoke.state=="playing" then --enemyx.hitsmoke:stop() --end break end else --enemyx.alpha=1 --if enemyx.hitsmoke.state=="playing" then --enemyx.hitsmoke:stop() --print ("emitter should be stopped now") --end -- TEST: if enemyx and enemyx.isVisible and enemyx.hitsmoke and enemyx.hitsmoke.state=="playing" then enemyx.hitsmoke:stop() end end end -- version 2.2 update end if laserweapon visible else -- enemyx and enemyx~=nil then ---if enemyx.hitsmoke.state=="playing" then ---enemyx.hitsmoke:stop() ---print ("emitter should be stopped now") --end if enemyx and enemyx.isVisible==true and enemyx.hitsmoke and enemyx.hitsmoke.state=="playing" then enemyx.hitsmoke:stop() end end end end
Here is the function code for CircleLineCollDetection which is used above:
CircleLineCollDetection = function (x1,y1,x2,y2, circlex, circley, circler) local x,y,dist for n=0,1,0.001 do x = x1 + ((x2 - x1) \* n) y = y1 + ((y2 - y1) \* n) -- old: --dist = sqrt((x - circlex)^2 + (y - circley)^2) --print ("first dist= "..dist) -- new: dist = ((x - circlex)^2 + (y - circley)^2)^0.5 if(dist \<= circler) then return true else -- DO NOTHING end end end
And the checkLaserEnemyHit function code:
local checkLaserEnemyHit = function (theenemy,newdamage,weapon) -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- \*\* removing the hp points and check for death and update text stats \*\* -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* local enemy=theenemy local enemymoney=enemy.deathmoney local enemyscore=enemy.scorePoints local hiteffect if enemy and enemy.resistance and enemy.resistance==2 then -- do nothing because the enemy has a res for this weapon! else if enemy and enemy.statusbarFill and enemy.hitpoints and enemy.maxhitpoints then enemy.hitpoints=enemy.hitpoints-newdamage newscaleval=enemy.hitpoints/enemy.maxhitpoints if newscaleval\>0 then enemy.statusbarFill.xScale=newscaleval if newscaleval\>=0.6 then enemy.statusbarFill:setFillColor( \_G.appleDesignColor4\_R,\_G.appleDesignColor4\_G,\_G.appleDesignColor4\_B) elseif newscaleval\>=0.3 and newscaleval\<0.6 then enemy.statusbarFill:setFillColor( \_G.appleDesignColor2\_R,\_G.appleDesignColor2\_G,\_G.appleDesignColor2\_B) elseif newscaleval\<0.3 then enemy.statusbarFill:setFillColor( \_G.appleDesignColor1\_R,\_G.appleDesignColor1\_G,\_G.appleDesignColor1\_B) end end end end -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* if enemy.hitpoints\<=0 and enemy.isAttackable==true and enemy.isVisible==true then -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- \*\* The Enemy is dead now \*\* -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* enemy.isVisible=false enemy.isAttackable=false --.isAttackable enemy.newEnemySprite:setSequence ((enemy.name.." Death")) enemy.newEnemySprite:play() -- stop a possible laser smoke from the enemy if enemy.hitsmoke then if enemy.hitsmoke.state=="playing" then enemy.hitsmoke:stop() end end -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- \*\* If this was the target Enemy for the weapon \*\* -- \*\* we have to set back the target value here \*\* -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* if enemy==weapon.lockedOnEnemy then weapon.lockedOnEnemy=nil end -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- \*\* Show Enemy Explosion now \*\* -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* func.explodeEnemy(enemy) composer.state.money=composer.state.money+enemymoney composer.state.levelscore=composer.state.levelscore+enemyscore updateMoneyText (composer.state.money) updateScoreText (composer.state.levelscore) else -- means the enemy was hit but NOT destroyed yet -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- \*\* looking up the type of weapon first \*\* -- \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* -- not used! end
