I am using the SSK2 camera and I have come across a problem. I created a function to stop the camera when it approached the end of my scene so the black area does not appear. But I keep getting this error when stopping the camera:
ERROR: Runtime error ERROR: nil key supplied for property lookup. stack traceback: [C]: ? ?: in function 'removeEventListener' ?: in function 'removeEventListener' ?: in function 'removeEventListener' ssk2/easyCamera.lua:138: in function 'stopCamera' main.lua:143: in function '?' ?: in function \<?:190\>
I believe it has something to do with my group, as the line in the easyCamera.lua that is referred to in the stack traceback removes the event listener from the group. This is the function I created:
function fixCamera() if map.designedWidth - anim.x \< 1115 then anim.isCameraActive = false anim:stopCamera() --Line 143 (Error Line) elseif map.designedWidth - anim.x \> 1115 and anim.isCameraActive == false then ssk.camera.tracking(anim, group, {lockY = true}) end end
If any more code is needed please ask.
Thank you!
PS, @roaminggamer, Thanks for the awesome camera system!
I am pretty sure I am not stopping it twice. I searched for it in my file and its only location is in the fixCamera function.
I tried the code the same error appeared:
function fixCamera() if map.designedWidth - anim.x \< 1115 and display.isValid(anim) then anim.isCameraActive = false anim:stopCamera() elseif map.designedWidth - anim.x \> 1115 and anim.isCameraActive == false then ssk.camera.tracking(anim, group, {lockY = true}) end end
function trackObj.stopCamera( self ) ignore("enterFrame", world) world:removeEventListener("finalize") world.finalize = nil end
Please replace it with this:
function trackObj.stopCamera( self ) if( isValid(world) ) then ignoreList( {"enterFrame"}, world ) if( world.finalize ) then world:removeEventListener("finalize") world.finalize = nil end end end
Then, try it out and let me know if this solves the problem.
Thank you very much for that code, it worked perfectly. As for the camera check, it is only adding and removing one camera, as I drag the player in and out of the 1115 boundary.
Also, presume I have a character off the screen on some devices but on screen on other devices, I know I can change the default X and Y tracking position so is it possible to show the character on the “not working” screens, but leave it as it is on the “good screens”? I know there is a difference between actualContentwidth and contentWidth, could I use one of these to my advantage?
Thank you for the help, but this will not work in my case as the player starts at the far left of the scene and centering it will show the black area on the left side.
Bad news. I don’t have time to teach you or do it for you.
Sorry boss.
Suggestion. Start with the basic camera and work it out. Almost all of the important code changes (not many) will be in the enterFrame call:
-- == -- tracking() - Follows target exactly. -- == function camera.tracking( trackObj, world, params ) if( not isValid( trackObj ) ) then return end if( not isValid( world ) ) then return end params = params or {} local lockX = params.lockX local lockY = params.lockY local centered = fnn( params.centered, false) local lx = 0 local ly = 0 if( centered ) then if( lockX ) then lx = trackObj.x else lx = centerX end if( lockY ) then ly = trackObj.y else ly = centerY end else lx = params.lx or trackObj.x ly = params.ly or trackObj.y end world.enterFrame = function( event ) local dx = 0 local dy = 0 if(not lockX) then dx = trackObj.x - lx end if(not lockY) then dy = trackObj.y - ly end if(dx ~= 0 or dy ~= 0) then world:translate(-dx,-dy) lx = trackObj.x ly = trackObj.y end return false end listen( "enterFrame", world ) world.finalize = function( self ) ignoreList( { "enterFrame" }, self ) end; world:addEventListener( "finalize" ) function trackObj.stopCamera( self ) if( isValid(world) ) then ignoreList( {"enterFrame"}, world ) if( world.finalize ) then world:removeEventListener("finalize") world.finalize = nil end end end end