getting current scene dimensions?

  • #1, by rhavin grobertSunday, 05. November 2017, 21:35 3 years ago
    Tried the following:

      local scene = game:getLink(VGameCurrentScene)
      print ("--- start ---")
      for v,t in pairs(scene.SceneScrollableArea) do
        print (v,t)
      end
      print ("--- end ---") 
    1
    2
    3
    4
    5
    6


    message.log is

    21:31:24.814:--- start ---
    21:31:24.814:y 0
    21:31:24.814:x 0
    21:31:24.814:height 0
    21:31:24.814:width 0
    21:31:24.814:--- end ---
    1
    2
    3
    4
    5
    6

    of course, the scene actually *is* a bit bigger wink

    So, how do i get the dimensions of the current scene?

    Newbie

    47 Posts


  • #2, by sebastianSunday, 05. November 2017, 22:15 3 years ago
    You need the size of the background sprite. The scrollable area is "0"in width/height if it has no limits set (default).


    There is a function getSize() to return a size of a sprite.

    Use this:
    game.CurrentScene.Sprite:getSize().x
    game.CurrentScene.Sprite:getSize().y
    1
    2

    Thread Captain

    2337 Posts

  • #3, by rhavin grobertSunday, 05. November 2017, 22:18 3 years ago
    Ok, found something that I can use as a workaround by pure chance

    http://www.visionaire-studio.com/luadocs/#commands

    local scene = game:getLink(VGameCurrentScene)
    print(scene.SceneSprite:getSize().x)
    1
    2
    3


    Still, I actually want to know the dimensions of the (scrollable) scene, regardless of the sprite that might be smaller or bigger.

    From an OO point of view, getting the size of the scene has to be a method of the scene!

    Newbie

    47 Posts

  • #4, by ke4Sunday, 05. November 2017, 22:19 3 years ago
    Edit: I see Sebastian already answered razz

    SceneScrollableArea sets the limit how far you can scroll. You can limit that to 100px for example.

    ScrollPosition gives you how much is currently scrolled.

    WindowResolution will give you the game resolution.

    This could give you the scene size i suppose.

    game.CurrentScene.Sprite:getSize()
    1

    Key Killer

    810 Posts

  • #5, by sebastianSunday, 05. November 2017, 22:27 3 years ago
    From an OO point of view, getting the size of the scene has to be a method of the scene!
    The size of the scene is determined by the sprite you use there. And the sprite field for a scene is a link to the used image (and some other informations). 

    If you need the size of the actual scrollable area, you may need to create a function which checks if the scrollable area width/height is 0. If not, use that . If its 0, use the sprite size.

    Thread Captain

    2337 Posts

Write post