You could achieve this by creating your own module called camera_mod.lua with this in it:
-- camera\_mod.lua -- == -- tracking mode() - Follows target exactly. Added Pause -- == function ssk.camera.tracking\_mod( 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 ) if( world.\_cameraPaused ) then return false end 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.pauseCamera( self ) if( isValid(world) ) then world.\_cameraPaused = true end end function trackObj.resumeCamera( self ) if( isValid(world) ) then world.\_cameraPaused = false end end 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
function fixCamera() if( not anim.cameraAdded ) then anim.cameraAdded = true ssk.camera.tracking\_mod( anim, group, {lockY = true}) ) anim:pauseCamera() end if map.designedWidth - anim.x \< 1115 then anim:pauseCamera() elseif map.designedWidth - anim.x \> 1115 then anim:resumeCamera() end end
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