0 Favourites

WindowWidth Question

  • Hey,

    I have question about windowWidth parameter, I read couple of threads I could find but could not figure a solution.

    ok so scenario is this, I have two TiledBG-s for health hud.

    I want red one to be scaled to same size as playable window of the game (camera is fixed, does not move)

    I used RedTiledBG.width=windowWidth

    Then I have Health and Max Health, in event bellow I calculate what percentage of maxhealth is current health and then I translate this into hud.

    so if current health is 40% of max health, width for GreenTiledBG will be 40% of RedTiledBG width, which is turn should be equal of playable window width.

    <img src="http://i.imgur.com/V1Gemqu.png" border="0" />

    this works well and correctly when fullscreen in browser is set to "Off"

    but when its set to letterbox

    something like this happens

    <img src="http://i.imgur.com/JeGJphG.png" border="0" />

    I don't understand exactly whats going on here, but I know its being scaled somehow and windowWidth is behaving like it should from other threads.

    But in my case what alternative can I use to accomplish my task? is there anyway to capture actual playable area window width?

  • Hi Hellwalker,

    It seems to be a problem that affects only a certain group of people, who try to position elements at run-time ;-)

    There is a solution to it posted, e.g. here:

    scirra.com/forum/windowwidth-and-windowheight-not-working_topic49092.html

    but it's hard to find - and I found it very frustrating for a long time ;-)

    In brief:

    Create a global variables, e.g. ETWindowHeight, ETWindowWidth. Set them to the WindowHeight and Width as defined at edit time. From then on, use these to position your elements at runtime, rather than original variables.

    I think it would be nice if a similar solution was built into the engine - or maybe it is, but I don't know where to find it? ;-)

    Cheers,

    Greg

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Thanks Greg!

  • This is a common mistake. The window width is not the same as the viewport width.

    Window width = number of browsers horizontally in the browser window

    Viewport width = number of pixels showing horizontally in the layout, which is what you want.

    Scaling the view affects the viewport width, but not the window width.

    To get the viewport width, use ViewportRight("layer") - ViewportLeft("layer")

  • Fairly new so please bear with me.

    Goal: Non-ticking Grid Map that is always the height and width of the usable area inside a browser (cross device, cross resolution)

    Basically I'll:

    • AJAX load an XML of grid data
    • use a 32x32 TiledBackground
    • put Text objects in each grid box (destroy and re-create on resize)
    • on panning I'll clear all the text and cycle through them setting text to values from the appropriate portion of the XML

    So... No "real" panning, no scaling.

    WindowWidth, WindowHeight, ViewportLeft, ViewportTop do not seem to wait for Browser Object On Resized to complete and even when I put delays in they still do not seem to be the actual width / height or top / left of the browser window.

    I also see no way to dynamically set Layout or Viewport size or position.

    Edit time Project Window Size and Layout Size don't seem to matter.

    All browsers I've tested with seem to have the same issue.

    Current settings:

    Project

    Window Size 10,10 (since they don't seem to matter and want them dynamic anyway)

    Fullscreen in browser: Crop

    Enable WebGL: Off (strictly 2d canvas that I want to be fast response)

    Layer

    Scale Rate: 0

    Parallax: 100,100 (since I can't turn it off?)

    Parallax in editor: No

    Layout

    Unbounded scrolling: No

    Layout Size: 10, 10

    Margins: 0, 0

    Currently I call a "DrawScreen" function from 2 events

    • System: On Start of Layout
    • Browser: On Resized

    This "mostly" works but seems to be % off (10 to 100 pixels depending on browser window size)

    Also, when I put logging in, the dimension variables don't "settle" immediately.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
353 32,082
yojona's avatar
yojona
Unread sticky
192 1,337,417
Kyatric's avatar
Kyatric Construct Team Support
Unread hot topic Locked topic
67 21,583
Ashley's avatar
Ashley Construct Team Founder