Kulissenscrolling

  • #1, by rhavin grobertThursday, 02. November 2017, 16:13 2 years ago
    Hallo Leute,

    ich fang grad mit VS an, und hab gleich mal 'ne Frage:

    Ich hab eine Kulisse, die einen U-bahn-Wagen darstellt. Nun soll die Kamera immer auf die Person gerichtet sein, solange dafür der Hintergrund nicht über seine Grenzen gescrollt werden muss, und der Vordergrund soll entsprechend mit 110% gescrollt werden.

    Wie kann ich das umsetzen? Mit den Einstellungen im Studio bekomme ich zwar das 110% scrolling hin, aber das Scrolling geschieht immer nur, wenn die Person den Bildschirmrand erreicht…

    VG, rhavin

    Newbie

    47 Posts


  • #2, by afrlmeThursday, 02. November 2017, 17:28 2 years ago
    A'llo,

    You can adjust the scroll distance with Lua script. Inside of the scene actions tab create an at begin of scene action (unless you already have one), now inside of this create an execute a script action part & now add this code to it...
    game.HorizontalScrollDistance = (game.WindowResolution.x / 2)
    game.VerticalScrollDistance = (game.WindowResolution.y / 2)
    1
    2

    This should force the engine to always scroll when the character moves.

    You might want to create an at end of scene action too under the scene actions tab & create an execute a script in that so that you reset the scrollable areas back to their default values when you leave that scene.
    game.HorizontalScrollDistance = 100
    game.VerticalScrollDistance = 100
    1
    2

    Imperator

    6771 Posts

  • #3, by rhavin grobertThursday, 02. November 2017, 18:37 2 years ago
    Thx for the answer.Lets say in lua I have something like that:
    local sx, sy
    function CenterActor()
      sx = game.HorizontalScrollDistance
      sy = game.VerticalScrollDistance
      game.HorizontalScrollDistance = (game.WindowResolution.x / 2)
      game.VerticalScrollDistance = (game.WindowResolution.y / 2)
    end
    function ReleaseCenter()
      game.HorizontalScrollDistance = sx
      game.VerticalScrollDistance = sy
    end
    function foo(bar)
      -- do something with bar
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    How can I call those funtions? and how can I give arbitrary values like in the third fn? I just found the setting ›call script‹ and ›execute script‹. I assume as the call option just let me call scripts that have top-level functionality, that I have to enter the function-call manually inside the body of ›execute script‹. How do I do this? Something like 

    Scripts.myScriptName.CenterActor()

    doesn't seem to work.

    Newbie

    47 Posts

  • #4, by afrlmeThursday, 02. November 2017, 18:56 2 years ago
    If you want to create functions then create scripts in the script section of the editor. Leave them as definition type scripts so that they are defined & can be called as soon as the game is launched rather than having to be manually called in.

    Now to call/update functions you can create execute a script actions anywhere in the editor where you can create action parts. Anyway in those you can just type the function name you want to call...
    centerActor()
    1


    Here's a quick example of a function with input variables...

    Add this as a definition script.
    function test(str,n)
     for i = 1, n do
      print(str)
     end
    end
    1
    2
    3
    4
    5

    Now you can call & execute this function inside of an execute a script action part or from another script or inside of another function..
    test("I should not swear at the teacher.", 10) -- will write "I should not swear at the teacher." 10x to the log
    1

    Imperator

    6771 Posts

  • #5, by jensvdgrinten-kreativ-blockFriday, 03. November 2017, 19:01 2 years ago
    Ich hab mich selber noch nicht damit auseinandergesetzt, aber wäre es möglich per Aktionsbereich die Kulisse zu "schieben"?

    Newbie

    34 Posts

  • #6, by rhavin grobertSaturday, 04. November 2017, 00:01 2 years ago
    Still does not work.

    See this:

    [###ooo]o###
    [] = screen-size. o & # : scene area

    As long as the charakter is in the "o" area, he should walk but stay in the middle of the screen. Instead, the scene should scroll. If the char enters the "#" area, he should walk to the edge.


    --- OK found it, must be

    game.GameHorizontalScrollDistance = (game.WindowResolution.x / 2)

    Well, I hope some dev is now consolidating the API grin

    Newbie

    47 Posts

  • #7, by afrlmeSaturday, 04. November 2017, 00:54 2 years ago
    Yeah sorry. My bad. I quickly typed it out & didn't take into consideration that it was a single field rather than a table with point (x & y) entries.

    Imperator

    6771 Posts

  • #8, by rhavin grobertSaturday, 04. November 2017, 01:02 2 years ago
    Yeah sorry. My bad. I quickly typed it out & didn't take into consideration that it was a single field rather than a table with point (x & y) entries.
    Not your fault (unless you're a dev of this engine, of course ;-)

    It should be either (as stated in the doku):

    game.GameHorizontalScrollDistance = (game.GameWindowResolution.x / 2)

    or

    game.HorizontalScrollDistance = (game.WindowResolution.x / 2)

    Incohærent field value naming is bad. Someone should fix this.

    Newbie

    47 Posts

Write post