Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

SSK2: Reset camera offset after it has been stopped
Started by sdktester15 Jun 27 2018 11:04 AM

2 replies to this topic

Best Answer sdktester15 , 27 June 2018 - 11:59 AM

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

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sdktester15

[GLOBAL: userInfoPane.html]
sdktester15
  • Corona Geek

  • 1,142 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,748 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

sdktester15

[GLOBAL: userInfoPane.html]
sdktester15
  • Corona Geek

  • 1,142 posts
  • Corona SDK

  Best Answer

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

  • roaminggamer likes this


[topic_controls]
[/topic_controls]