0 Favourites

Always in Centre

  • I am trying to load up a game on my mobile device. At the moment, I have a title screen that is in the centre of my layout, however, while it works fine on one mobile device, the other appears to be ever so slightly larger, and so when the game loads, the title is no longer in the centre.

    Any idea how to go about this?

    I tried setting the position based on the window size, but that doesn't appear to work at all. I only get a result if it's based on the layoutwidth/2, but that doesn't work when the game is on the bigger screen.

    I should point out that I'm using CocoonJS... and it hates letterbox scale... for some daft reason. Who really uses Scale Outer?

  • I always use scale outer, because I hate black lines around my game-screen.

    To set in the center you could just set it in the center of a 0,0 paralex layer.

    Also you could base your position on the edges of the screen.

  • LittleStain

    Not sure you've experienced the same as me...

    There is no centre if the screen size keeps changing. I need to do this at run time so that I can support a lot of screen sizes. With scale outer, it doesn't scale from the centre, it scales from an edge.

    I could add it to a parallax layer, but if I don't know how many pixels the screens are different by, it's no use to me.

    In this example, it could be anywhere between 100-200 pixels, but of course, there's no real way of knowing.

    I'd have thought window width would be what I need... but it doesn't work at all, even in my C2 previews.

  • Never had that problem.

    Set the layout to unbounded scrolling and one layer to paralex 0,0 and everything stays in it's place.

    Another way would be to use viewportleft, viewportright, viewporttop and viewportbottom expressions.

  • LittleStain

    Not sure you've experienced the same as me...

    There is no centre if the screen size keeps changing. I need to do this at run time so that I can support a lot of screen sizes. With scale outer, it doesn't scale from the centre, it scales from an edge.

    I could add it to a parallax layer, but if I don't know how many pixels the screens are different by, it's no use to me.

    In this example, it could be anywhere between 100-200 pixels, but of course, there's no real way of knowing.

    I'd have thought window width would be what I need... but it doesn't work at all, even in my C2 previews.

    You could use the viewportLeft(layer), viewportRight(layer), viewportTop(layer) and viewportBottom(layer) expressions to get the center at runtime

  • Does this work as expected?

    online example

    Center.capx

  • LittleStain - Just testing your solution first with parallax and unbounded... but I do not think that will work. While it's compiling through Ludei, I've given viewportright/2 a go, and it's put it in the centre... I just need to test that on my compiled APK and see if that worked.

  • I would suggest using: viewportleft+((viewportright-viewportleft)/2)

    Otherwise it will only work when viewportleft is 0

    Could you explain why the example I posted wouldn't work?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • AnD4D,

    Try this for size - capx

    I usually set a representation of the minimum screen size and maximum aspect ratio that I am planning to support and make it invisible - but it will be there at edit time so I can position things how I want. I also resize my HUD objects in the editor so they are smaller than their true pixel size. This allows them to scale up to higher resolutions and keep some definition.

    If you want to use the viewport technique I have in this example then the objects need to exist in the layout before they are moved with reference to their width and height (the scaling is then taken care of, so they move and resize as you would like with different screen resolutions).

  • LittleStain

    I am genuinely surprised. That actually worked. Not sure how...

    However, it did break an awful lot of my game. One example is that I had an event that would delete anything that went off screen, so things would randomly disappear when they got too close to the edge.

    Just testing out the viewport suggestion, then I'll give Colludium's a go :)

  • viewportleft+((viewportright-viewportleft)/2) worked great! I'll use this for future games.

    Colludium

    That is very interesting indeed. Very clever idea for huds for multiple screen sizes. All you'd need to do is run the function at the beginning, and you're set!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)