Getting width of scene

  • #1, by BenmirathFriday, 18. October 2013, 21:04 11 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 11 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

    1581 Posts

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

    Newbie

    31 Posts

  • #4, by LebosteinMonday, 29. June 2015, 11:51 9 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

    621 Posts

  • #5, by afrlmeMonday, 29. June 2015, 13:37 9 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
    

    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

    7278 Posts

  • #6, by LebosteinMonday, 29. June 2015, 13:41 9 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

    621 Posts

  • #7, by afrlmeMonday, 29. June 2015, 17:43 9 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
    

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

    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
    

    Imperator

    7278 Posts

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

    Key Killer

    621 Posts

  • #9, by afrlmeTuesday, 30. June 2015, 01:27 9 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

    7278 Posts