Smooth scrolling / panning

  • #1, by AkcayKaraazmakSaturday, 06. September 2014, 08:36 10 years ago
    When the character starts moving to edge of the scene, scenes are panning/scrolling. But how we could do that sliding smoothly. Camera start up with a speed and then slow down towards the end?

    Great Poster

    440 Posts


  • #2, by SDMonoSaturday, 06. September 2014, 11:35 10 years ago
    It might be possible via LUA but I am not sure. Would love to see an option for that!!! Signed!!

    Forum Fan

    148 Posts

  • #3, by AkcayKaraazmakSaturday, 06. September 2014, 11:41 10 years ago
    Yea mate, an option would be great! Lee told me that there are some tween parameters but they could only be accessed via LUA as you wrote.

    Great Poster

    440 Posts

  • #4, by SimonSSaturday, 06. September 2014, 12:20 10 years ago
    You can try my test script, I'm not completely happy with the result, but it's enough for some games:
    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")
    

    Thread Captain

    1582 Posts

  • #5, by AkcayKaraazmakSaturday, 06. September 2014, 12:29 10 years ago
    Thats cool mate, thank you so much!. I'll give a try on it. But how I gonna execute it? In what action, should I write it of execute script? I'm a very beginner level in Vs.

    Great Poster

    440 Posts

  • #6, by SimonSSaturday, 06. September 2014, 12:47 10 years ago
    Go to scripts, create a script (you can name it what you want), paste it, the script should be marked as definition script, what's the default case.

    Thread Captain

    1582 Posts

  • #7, by SDMonoSaturday, 06. September 2014, 18:44 10 years ago
    Thanks SimonS... gonna try it out and get back to you! smile

    Forum Fan

    148 Posts

  • #8, by SDMonoSaturday, 06. September 2014, 20:01 10 years ago
    I played around with the "delay" and the "if dist"... somehow it work and it looks a lot smoother but sometimes it just won't scroll even though my character is leaving the screen border and there is still a little part of the background off screen.

    Forum Fan

    148 Posts

  • #9, by unrealSaturday, 06. September 2014, 20:55 10 years ago
    I was looking for this kind of script, thanks a lot SimonS ! wink

    Newbie

    66 Posts

  • #10, by SimonSSaturday, 06. September 2014, 21:09 10 years ago
    @SDMono: it's just a test script, needs a lot of tweaking for every game. Problem is, when distance is too high it won't scroll to some parts at the edge, too low and it will restart the scrolling to often, I tried it with the big scene in Whispered World, that worked nicely with these values. But I can't use magnetism to the edge of the scene because we can't get size of the background image yet...

    Thread Captain

    1582 Posts

  • #11, by SDMonoSunday, 07. September 2014, 18:27 10 years ago
    Would there be a way of changing the scrollspeed via LUA "game:setValue(VGameScrollSpeed, 200)" and increase it while the scrolling is going on?

    Forum Fan

    148 Posts