Centreing an actor with an equal amount of space around it for all devices

KevinCrossKevinCross London, UKMember Posts: 1,894
edited February 2016 in Working with GS (Mac)

I've been struggling with this for most of the week now so was hoping someone would be able to help out.

In my project I'm trying to centre a grid made up of single actors and have it remain in the centre for all resolutions/devices. I've created a simple project to show the problem. This project has only one actor but the principle is the same. The individual square size in the grid is based on screen size / 10. That way I'm always going to have 10 squares high visible on the screen. This works, and if you switch between the different devices/resolutions you'll see that working. After I've calculated the size of the square I'm creating the scene size to be square size * 20 and then adding the height of the device to the scene height and the width of the device to the scene width.

I'm then calculating the difference between the scene size and the grid size and halving that difference to get an offset. That offset is then used to centre the grid. On the original scene device (iPad) it works fine. But as soon as you switch to another device like iPhone 6 the border around the grid is different on all sides. I should mention that I know that I could just centre this one actor with self.Position.X = scene.Size.Width / 2 etc. but as I've mentioned my main project grid is made up off lots of actors.

In the main project I'm using the universal build formula by Lovejoy but still not having much luck. Nothing wrong with his formula I just can't find the right place to implement it. I've tried adding/subtracting it to the scene size, as well as trying adding/subtracting it to the offset etc. His formula is in the example I've attached to this post.

I was hoping to find one block of code that works for all resolution sizes instead of having to write individual rules for all devices.

Thanks in advance

P.S. by the way you can pan around the scene by dragging/swiping. And when viewing all devices in the viewer please choose Overscan to see what I mean

Comments

  • zweg25zweg25 Member Posts: 738

    I have not pinpointed the problem, but at a quick glance it looks like its the movement of the pannable background actor, not the placement and size of the grid. You may have already knew that though

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    @zweg25 said:
    I have not pinpointed the problem, but at a quick glance it looks like its the movement of the pannable background actor, not the placement and size of the grid. You may have already knew that though

    Thanks. I didn't think about that being the problem! You've given me an idea on a few things to check/test now. Hopefully I'll get a few minutes to look at it today otherwise it'll probably be early next week.

    Again thanks for the suggestion.

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited February 2016

    Just had a quick look and can see that the grid is centred on the pannable background which is centered on the scene (I can tell by how much of the black arrows are inside the grid on all 4 sides) so it looks like you're definitely right about the code on the pannable background being incorrect (that background doesn't actually move). It'll be a problem with the min and max functions. I will have to add or subtract an offset to this code somehow that works for all resolutions.

  • DuesDues Member Posts: 1,159

    Take a look at this method that @Lovejoy created:

    http://forums.gamesalad.com/discussion/86157/my-universal-binary-overscan-secret-weapon/p1

    Not sure if that's what you are after? :)

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited February 2016

    @Dues said:
    Take a look at this method that @Lovejoy created:

    http://forums.gamesalad.com/discussion/86157/my-universal-binary-overscan-secret-weapon/p1

    Not sure if that's what you are after? :)

    Yeah I got that formula in my examples. @zweg25 has identified the problem with it being the pannable background actor and the Camera.Origin code. I've since fixed the border at the left and bottom of the scene by adding @Lovejoys formula to the max part of the min/max expression, but still can't fix the top and right of the scene. I know it's the min part of the expression that needs amending.

    I'm going to create a min/max expression for each resolution/device and play around with the numbers until I get an expression created for each that works for each device and then see if I can find a pattern to get one expression that fits all. I'm definitely closer now. If I do nail it next week I'll upload a new version in case anyone else would find it useful.

  • DuesDues Member Posts: 1,159

    Sorry, didn't read through the whole post

    Bad Dues

    Slaps head like Gollum

    :)

  • zweg25zweg25 Member Posts: 738

    Glad you are closer to getting it. If you are still working on it tonight I will take a closer look at those min/max functions

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    Thanks @zweg25 but I'm not going to be able to work on it until early next week now. If you get like 2 minutes spare and have a look before then then that would be appreciated but no probs if not. I'm sure I'll get it in the end :)

  • zweg25zweg25 Member Posts: 738

    Cool, looked into it and fixed it. You said you were going to upload the version when you fix it so I hope you don't mind if I share it over this post. If so, I will take it down and give it to you another time. Basically you weren't accounting for the size of the camera remaining at 1024x768.

    Hope this helps!

  • zweg25zweg25 Member Posts: 738

    PS: when you test it on the creator make sure it is zoomed at 100% instead of 50%

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    Hi @zweg25 I'm not able to look at it for a couple of days, but thanks a lot for your help and finding a fix :) you've probably saved me a couple of evenings of head scratching. Very much appreciated.

    And no I don't mind you sharing it. It's bound to be useful to other people that work with large scenes

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    It's 5AM. I'm staying at a friends house. Their heating is on full blast! Can't really sleep so thought I'd have a look at your version of the file. It works perfectly, so once again thank you.

    I don't really know how you came up with the dividing by 8 part of the expression and it would probably take me a couple of wasted evenings trying to work it out lol but I can see removing it breaks it so will except it as magic and now try and convert this to my original project.

    I hope someone else finds it useful!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @KevinCross said:
    I hope someone else finds it useful!

    Yup! Useful, useful, useful!

    Thanks @KevinCross for bringing it up.
    And thanks to @zweg25 for working on it and figuring it out.

  • zweg25zweg25 Member Posts: 738

    My pleasure. I found that the way it was setup it would start 96 pixels below the screen. That was the same as 768/8 so I just put that in because it may have had a significance that I didn't find.

Sign In or Register to comment.