SSK2: Reset camera offset after it has been stopped

I am calling the stopCamera function in the hide function of my scene, but what I have found is that the camera’s offset is still present after I leave the scene and return to it.

When I try to reset my character’s position to centerX, centerY, technically it is reset, but, the camera offset is still present. 

So, say the character has moved to the left by 100 pixels, and so has the camera. (I have the centered parameter set to true) If I reset to say 200, 200, the character will actually appear at 300, 200. 

Is there any way of resetting the camera’s offset? Thank you.

  1. Technically, the SSK camera system is very basic and not meant to be restarted.  Stop() is really just meant to detach the camera listener so it doesn’t crash the game by continuing to run when the focus object is destroyed.

  2. You have the code…  So I suggest digging into it and finding out how to ‘reset the offset’.

  3. I’m busy now, but if you don’t post back with a “I solved it” post, I’ll probably take a look.

Hey, I did it! Thanks for the encouragement.

local totalOffsetX = 0 local totalOffsetY = 0 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 totalOffsetX = totalOffsetX + dx totalOffsetY = totalOffsetY + dy 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 world:translate(totalOffsetX, totalOffsetY) ignoreList( {"enterFrame"}, world ) if( world.finalize ) then world:removeEventListener("finalize") world.finalize = nil end end end
  1. Technically, the SSK camera system is very basic and not meant to be restarted.  Stop() is really just meant to detach the camera listener so it doesn’t crash the game by continuing to run when the focus object is destroyed.

  2. You have the code…  So I suggest digging into it and finding out how to ‘reset the offset’.

  3. I’m busy now, but if you don’t post back with a “I solved it” post, I’ll probably take a look.

Hey, I did it! Thanks for the encouragement.

local totalOffsetX = 0 local totalOffsetY = 0 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 totalOffsetX = totalOffsetX + dx totalOffsetY = totalOffsetY + dy 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 world:translate(totalOffsetX, totalOffsetY) ignoreList( {"enterFrame"}, world ) if( world.finalize ) then world:removeEventListener("finalize") world.finalize = nil end end end