Getting width of scene

  • #1, by BenmirathFriday, 18. October 2013, 21:04 7 years ago
    Hi,
    I'm creating a script that creates speech bubbles by the character talking. This is going well enough, but I have run into a slight issue with aligning the speech bubbles (held in an interface) to the correct facing while making sure they aren't clipped by the screen borders.
    My first inclination would be to determine the distance between the text origin (the main character) and the screen border, but I don't see any property like screen width or border to access via script. Is there such a property that I'm simply missing? Or is there something similar that I could fake it with, like the waypoint border or scrollable area scene properties?
    Thanks!

    Newbie

    31 Posts


  • #2, by SimonSFriday, 18. October 2013, 21:53 7 years ago
    Hello,
    the game always renders internally to the game's resolution and resizes that to your screen.
    http://wiki.visionaire-tracker.net/wiki/Data_Structure
    The object Game holds GameWindowResolution, that is the resolution.
    For the character position on screen you have CharacterPosition minus GameScrollPosition if your scene is scrolled.

    Thread Captain

    1369 Posts

  • #3, by BenmirathSaturday, 19. October 2013, 02:17 7 years ago
    Great, that seems like exactly what I was looking for, thanks!

    Newbie

    31 Posts

  • #4, by LebosteinMonday, 29. June 2015, 11:51 5 years ago
    How I can check if the character is outside the scene? On the left side this is no problem: Character.Position.x < 0. But on the right side? I need the background witdh of the scene: Character.Position.x > Scene.Width but the scene object stores no width...

    Key Killer

    601 Posts

  • #5, by afrlmeMonday, 29. June 2015, 13:37 5 years ago
    I wrote out the code for this in another thread yesterday. wink
    local ss = game.CurrentScene.SceneSprite.SpriteSprite:getSize()
    print(ss.x, ss.y) -- print scene width & height to log
    1
    2
    3

    P.S: I've not tested the code, but it should work.
    P.P.S: As I also mentioned: Simon said this shouldn't be called too often for some reason or another. It would be best called once at the begin of each scene & the value should be stored in a global variable, which can be accessed from anywhere, as & when it's needed.

    Imperator

    6842 Posts

  • #6, by LebosteinMonday, 29. June 2015, 13:41 5 years ago
    Ah, Thanks! The scene width = the background sprite width, I forgot.
    I need to call this function at the beginning of each scene, I hope this is not too often....

    Key Killer

    601 Posts

  • #7, by afrlmeMonday, 29. June 2015, 17:43 5 years ago
    Just write a small function inside of a script & then have it call the function inside of an at begin of scene action for each scene you need it for.

    script... (definition)
    function getSceneSize()
    ss = game.CurrentScene.SceneSprite.SpriteSprite:getSize()
    end
    1
    2
    3
    4

    usage... (execute a script inside of at begin of scene action)
    getSceneSize()
    1
    2

    Example of using scene size in another script....
    --[[
    in this example we are checking if scroll position is greater than the
    background size minus the default game resolution. Otherwise the
    background would be pushed out of the viewport. I know this isn't
    technically possible with the scroll position value, as it automatically
    corrects itself, but the viewport function of the shader toolkit however
    does require safeguards to prevent it from scrolling past the background
    on both x & y.
    --]]

    if game.ScrollPosition.x > (ss.x - game.WindowResolution.x) then
    game.ScrollPosition.x = (ss.x - game.WindowResolution.x)
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    Imperator

    6842 Posts

  • #8, by LebosteinMonday, 29. June 2015, 22:00 5 years ago
    This seems the correct code:
    function getSceneSize()
    ss = game.CurrentScene.Sprite:getSize()
    end
    1
    2
    3
    4

    Key Killer

    601 Posts

  • #9, by afrlmeTuesday, 30. June 2015, 01:27 5 years ago
    Sorry. Bit hard to know which is the correct path / table names when using shorthand. It's all a bit of a guessing game at the minute.

    Imperator

    6842 Posts

Write post