SSK2: Error when stopping camera

**MAY CONTAIN TYPOS**

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

Then, require this after you load SSK2:

require "ssk2.loadSSK" \_G.ssk.init() require "camera\_mod"

Then change your code as follows:

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

Elvis has left the building…

:lol:

Thank you very much! You didn’t even give me a chance to try it out.  :stuck_out_tongue:

I probably would have gotten stuck though.

  1. I’ll see if there is anything going on here.

  2. You forgot to tell me the version of SSK2 you’re running, but I assume it is 2017.010 or 2017.009?

  3. Are you sure you’re not stopping the camera twice?

  4. Try this:

    if( display.isValid( anim ) ) then anim:stopCamera() --Line 143 (Error Line) end

Sorry, the version is 2017.010.

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

Could it be the scope of the group?

No, it’s not a scope issue.

I’m in a meeting right now, but I’ll take a peek at my code after that.

Then I’ll write back.

Ok, thank you!

@sdktester15,

Please open ~/SSK2/ easyCamera.lua

One line 136 you will find this code:

 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.

Also, can you check that you are NOT adding multiple cameras?

E

function fixCamera() if map.designedWidth - anim.x \< 1115 and display.isValid(anim) then print("fixCamera() ===========\> REMOVING CAMERA") anim.isCameraActive = false anim:stopCamera() elseif map.designedWidth - anim.x \> 1115 and anim.isCameraActive == false then print("fixCamera() ===========\> ADDING CAMERA") ssk.camera.tracking(anim, group, {lockY = true}) end end

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?

That camera is designed to handle two basic cases:

  1. Player is on-screen and just where you want it.

  2. Player is not in the right place and you want it centered.

If #2 is OK, try calling it like this:

 ssk.camera.tracking(anim, group, {lockY = true, centered = true})

Question: Are you turning the camera on…off… on… off in the same level?

If so, It isn’t designed for that. 

It is meant to be turned on once and turned off once (just before removing the scene/level).

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.

Can I create a variable for the camera and lock its X when it comes into contact with the boundary?

This sounds like you need to write your own specialized camera.

You’re trying to co-opt a basic camera into doing more than it is meant to do.

The tracking camera is a single-shot basic camera.

Also, I’m not  understanding this motion  you want to achieve.  What good is a camera that stop tracking the player?

It would be great if I could do: 

local camera = ssk.camera.tracking(anim, group, {lockY = true}) if (conditions) then camera.lockX = true end

Alright, I will give it my best shot. Thank you again.

What I am trying to achieve, is to stop the camera before it shows a black area that is devoid of content. 

Good news.  I know how to do that.

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