What am I doing wrong here ? (Array of Objects)

Get help using Construct 2

Post » Mon Nov 11, 2013 9:33 pm

I want to make an universal transition between layouts using blocks (create an array of the same object). By universal, I mean to work well on all resolutions and aspect ratios. At 16:9 it works good, but on other resolutions/aspect ratios does not work correctly.

Here is the .capx file .

Also, how do I make the System to wait 0.3s after each Block is created ? I tried to put the action Wait X seconds in the loop, but it didn't worked.
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Mon Nov 11, 2013 9:56 pm

http://www.scirra.com/forum/topic79386.html
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Mon Nov 11, 2013 11:44 pm

@TELLES0808

So I will have to find a workaround for the action Wait X seconds ?
Also what is wrong with my loops that don't create objects where it should ?
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Tue Nov 12, 2013 12:15 am

In general:
A loop is executed within one tick. Trying to use the wait action would force C2 to spread the loop over several ticks, which not only is difficult, but also error-prone and would break the intention of a loop. That's why the wait action doesn't work inside loops.

You should always use a method suitable for the behavior you intended. If you want to create an object every 0.3 seconds, well, use "every x seconds"

I can't tell anything to the other problem as I avoid installing the newest versions. They often introduce new issues or break older behavior, which isn't helpful for projects that last longer to develop. But from your question I'd guess it is a mathematical problem? Maybe the positions are calculated in a wrong way.

Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Tue Nov 12, 2013 9:09 pm

I figured out what I was doing wrong: The size of the created objects was smaller then the actual object since the scale was smaller (smaller resolution = smaller scale).

Also I realized that my method is kind of stupid. A simple solution is to create the same number of objects regarding the resolution and set the object's size (not scale) based on resolution (If I want 7 objects on row and 5 objects on column then the Object.Width will be WindowWidth/7 and Object.Height will be WindowsHeight/5).

And the number of objects per row or column will be calculated depending on aspect ratio.
Does anyone know how to calculate the aspect ratio (formula) ?
B
49
S
15
G
6
Posts: 535
Reputation: 7,197

Post » Wed Nov 13, 2013 5:15 am

[QUOTE=TGeorgeMihai]Does anyone know how to calculate the aspect ratio (formula) ?[/QUOTE] um...width / height

16 pixel width, 9 pixel height -> aspect ratio = 16 / 9 = 1.77~ (or 1.77~:1)
32 pixel width, 24 pixel height -> aspect ratio = 32 / 24 = 1.33~ (or 1.33~:1)

Real life example:
You want 5x5 blocks. Display size is 640x480.
-> Aspect ratio 640 / 480 = 1.33~
-> 480 / 5 = 96
-> 96 * 1.33~ = 128
-> block size = 128x96

The shorter way is of course to just divide width and height by the number of blocks per row and column. EDIT: Ups, that's just what you do!

EDIT2: Or do you mean, you want the integer aspect ratio, as are seen on descriptions for monitor resolutions etc. (e.g. 4:3, 16:9, ...)? In case you do, this is done by calculating the greatest common divisor of both, width and height. Try the demo capx, it uses a recursive function to calculate the gcd: integer aspect ratiotulamide2013-11-13 05:43:48
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Wed Nov 13, 2013 8:32 am

Thanks @tulamide

The integer aspect ratio will be very usefull for what I want. I will do the following: There will be 6-7 blocks on Height(in landscape)/Width(in portrait). Using integer aspect ratio I will calculate how many blocks I need on Width(in landscape)/Height(in portrait) in order to maintain the block's proportion (square-ish).

But I've encountered another problem regarding Scale: http://www.scirra.com/forum/how-do-i-get-the-layout-scale_topic79444.html . Can you also help me on this one ?
B
49
S
15
G
6
Posts: 535
Reputation: 7,197


Return to How do I....?

Who is online

Users browsing this forum: jogindarpradeep, matriax and 17 guests