Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Getting width of scene

  • #1, by Benmirath 13 years ago Zitieren
    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!
  • #2, by SimonS 13 years ago Zitieren
    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.
  • #3, by Benmirath 13 years ago Zitieren
    Great, that seems like exactly what I was looking for, thanks!
  • #4, by Lebostein 11 years ago Zitieren
    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...
  • #5, by afrlme 11 years ago Zitieren
    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.
  • #6, by Lebostein 11 years ago Zitieren
    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....
  • #7, by afrlme 11 years ago Zitieren
    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
    
  • #8, by Lebostein 11 years ago Zitieren
    This seems the correct code:
    function getSceneSize()
     ss = game.CurrentScene.Sprite:getSize()
    end
    
  • #9, by afrlme 11 years ago Zitieren
    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.