c_res=game:getPoint(VGameWindowResolution)
sc_current={x=0,y=0}
sc_cur=0
function dist(x,y)
return math.sqrt(math.pow(x.x-y.x,2)+math.pow(x.y-y.y,2))
end
function center_char()
local c_position=game:getLink(VGameCurrentCharacter):getPoint(VCharacterPosition)
local c_scroll=game:getPoint(VGameScrollPosition)
local scene_changed=sc_cur~=game:getLink(VGameCurrentScene):getId().id
c_position.x=c_position.x
c_position.y=c_position.y
c_position.x=c_position.x-(c_res.x/2)
c_position.y=c_position.y-(c_res.y/1.5)
c_position.x = math.max(0,c_position.x)
c_position.y = math.max(0,c_position.y)
if dist(c_position,sc_current)>300 or scene_changed then
sc_current=c_position
local delay=3000
if(scene_changed)then
delay=0
end
startObjectTween(game, VGameScrollPosition, c_scroll, c_position, delay, easeQuadInOut)
sc_cur=game:getLink(VGameCurrentScene):getId().id
end
end
registerEventHandler("mainLoop", "center_char")