Always in Centre

Get help using Construct 2

Post » Thu Feb 13, 2014 11:43 am

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?
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
79
S
12
G
7
Posts: 963
Reputation: 10,721

Post » Thu Feb 13, 2014 12:23 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Feb 13, 2014 12:29 pm

@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.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
79
S
12
G
7
Posts: 963
Reputation: 10,721

Post » Thu Feb 13, 2014 12:40 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Feb 13, 2014 12:41 pm

[QUOTE=AnD4D] @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.[/QUOTE]

You could use the viewportLeft(layer), viewportRight(layer), viewportTop(layer) and viewportBottom(layer) expressions to get the center at runtime
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Thu Feb 13, 2014 12:45 pm

Does this work as expected?

online example

Center.capxLittleStain2014-02-13 12:47:22
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Feb 13, 2014 12:58 pm

@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.
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
79
S
12
G
7
Posts: 963
Reputation: 10,721

Post » Thu Feb 13, 2014 1:03 pm

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?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Feb 13, 2014 1:12 pm

@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).Colludium2014-02-13 14:12:23
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,205
Reputation: 43,832

Post » Thu Feb 13, 2014 1:20 pm

@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 :)
@bearboxmedia
www.bearboxmedia.com

Nintendo Wii U Developer using Construct 2
B
79
S
12
G
7
Posts: 963
Reputation: 10,721

Next

Return to How do I....?

Who is online

Users browsing this forum: plinkie and 17 guests