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

0 favourites
  • 7 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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.

  • 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 ?

  • 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.

  • 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). <img src="smileys/smiley2.gif" border="0" align="middle" />

    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) ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Does anyone know how to calculate the aspect ratio (formula) ?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 ratio

  • Thanks tulamide <img src="smileys/smiley32.gif" border="0" align="middle">

    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 ? <img src="smileys/smiley1.gif" border="0" align="middle">

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