How do I recalculate positions, depending on window size

Get help using Construct 2

Post » Fri May 05, 2017 8:19 am

Hey there!

I got a question about responsive design. So i got a fix screen size and i got a puzzle game, where the tiles will be sortet around the center of the screen. If the player changes the window size (brower window) would it be possible to recalc the position of the tiles, depending on the new window size? (The tiles should move to the right position)

i dont want to scale down the game canvas, the tiles should be new calculated.

I would need a behaviour which recognizes, if there is a new window size or something.

Thank you very much.
B
9
S
2
Posts: 148
Reputation: 1,043

Post » Fri May 05, 2017 9:21 am

You could look into the Anchor behavior.

Otherwise, WindowWidth and WindowHeight are system expressions you will want to use in the calculation of your tile's positions.

The exact calculation depends on how many tiles you have and how you have set them already (through code or not ?)
Provide your capx to get a more accurate answer in regards to how it is set up.

Otherwise, check the How do I FAQ to see how to make a grid of tiles through events. This could help out.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
294
S
117
G
96
Posts: 7,310
Reputation: 71,084

Post » Fri May 05, 2017 9:45 am

@Kyatric

Thanks for your fast answer. Iam currently using the anchor behaviour, but this isnt working pretty well with litetween (if its activated, there is no tweening possible - because of the anchor behaviour). I disalbed, and enabled the anchor behaviour to tween the sprite, but i get an offset after activating the anchor again. And iam not sure why - so this combo isnt a good solution.

Is there an option to run a function, if the window size is changed? I could code to reposition the sprites by myself. Do you know the best method to code the anchor behaviour?

I would share the capx, but i cant, because its a project fo a customer.
B
9
S
2
Posts: 148
Reputation: 1,043

Post » Fri May 05, 2017 12:24 pm

So basically a solution where i could set the size of my objects depending on the ratio of the viewport size...

That would be helpful...
B
9
S
2
Posts: 148
Reputation: 1,043


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests