0 Favourites

How do I do save and load object positions from an array

  • edit: changed titled as it makes more sense.

    I've included an capx example of how far I've got and how on what I'm trying to achieve: https://dl.dropboxusercontent.com/u/121 ... array.capx

    Basically the intent is to load instanced sprites into existence and various desired positions. If there is a way to store all this info into a single array then load all the instances via create object that would be excellent. Create Object woodbrick on Layer 2 at (1, 2)(2,4),(3,6).....

    Could someone please explain or illustrate, how I create instances of objects at x & y positions, possibly with the extension of angles. With a better method than I'm manually doing here? I plan to have various size shapes, so simply loading them to replace another sprites position (such as in the inventory array example) will unfortunately not do.

    Any help would be greatly appreciated.

    Edit: If anyone is willing and able to create a Create Object Array Plugin that would be amazing <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green"> <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green"> <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green"> . Basically being able to create an instance at multiple positions.

    You could select multiple sprites on the canvas, then save them to an array/group, for:

    Example: Create Object woodbrick on Layer 2 at (1, 2)(2,4),(3,6)..... creating an instance at all three or more locations.

  • adcornaglia

    This tutorial might help you: (remove spaces from link)

    scirra.com tutorials/ 748/record-and-rewinds-system-similar-to-braid

  • adcornaglia

    This tutorial might help you: (remove spaces from link)

    https://www.scirra.com/ tutorials/ 748/record-and-rewinds-system-similar-to-braid

    Programmer25

    Thank you very much for your reply, that is a really interesting system. Though, that isn't exactly what I'm trying to do, or I'm not understanding the parallel.

    I've included an capx example of how far I've got and how on what I'm trying to achieve: https://dl.dropboxusercontent.com/u/121 ... array.capx

    Basically I want to:

    0. Place objects on the layout.

    1. Record the positions of instances and objects into an array.

    2. Download the array as a XML/JSON file

    3. Then load the array of positioned object sets dynamically.

    Issues:

    â—‹ How do also I add instances of objects into the array?

    â—‹ How do I spawn the entities/objects/instances into the desired positions on a layout from the array?

    â—‹ Is there an easier way to save a selection of individual objects properties into an array?

  • adcornaglia

    I started learning Construct 2 about 5 days ago. Im very sorry I dont know how to help you.

    DaniellMesquita Can you have a look? Maybe you know how to solve this problem

  • Here is a sample capx of prefab. In this capx, it

    1. save position of all instances in layout 1 in a JSON string using rex_fncallpkg.

    2. goto layout2, create instances by the JSON string saved in step1.

    The idea is, transfer function calling of creating an instance into a string, then parse it and run the function calls. Therefore designer can save properties like position, angle, private variables, or properties of other instances in the same container.

  • Here is a sample capx of prefab. In this capx, it

    1. save position of all instances in layout 1 in a JSON string using rex_fncallpkg.

    2. goto layout2, create instances by the JSON string saved in step1.

    The idea is, transfer function calling of creating an instance into a string, then parse it and run the function calls. Therefore designer can save properties like position, angle, private variables, or properties of other instances in the same container.

    rexrainbow

    Yes, I have this plugin from you and your many other great plugins.

    That said, I would like to learn how to achieve this without a plugin as I have need more practice with arrays and understanding how to do this will better equip me for solving my own problems in the future. I would greatly appreciate it if you would be able to guide me in this way.

    I'm still stuck at these issues:

    ? How do also I add instances of objects into the array?

    ? How do I spawn the entities/objects/instances into the desired positions on a layout from the array?

    ? Is there an easier way to save a selection of individual objects properties into an array?

  • Example capx (2017-05-11).

    For "push" to work properly, you need to be sure to set the size (width) of the array to 0 in the first place.

    Then Width - 1 corresponds to the maximum X index you can reach in your array.

  • That works! I might try to use this in my project although i dont need it, just for the sake of making it more complex

  • Example capx.

    For "push" to work properly, you need to be sure to set the size (width) of the array to 0 in the first place.

    Then Width - 1 corresponds to the maximum X index you can reach in your array.

    Thank you, I was certainly not doing it right. I needed a visual example to get how to use the array here. This will help me do my bonus mode and some of the stage effects I need. So, I'll definitely be putting it to good use ??

  • Kyatric

    hi man, do you have your Capx yet? link is broken.

  • mostafanastary: I modified the link in my previous post, it is now working.

  • Hi. Thanks for making this thread. Is useful, and the answers are interesting. I'm trying another variation of this.

    In my case, i want to make a lot of imagepoints for instances, and i wonder if this is the best option and how to do it.

    I want to save and load these coordinates and able to call it with and without leaving the current layout.

    How do i do that?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Avengium, you can do it with 2D array, store [object type, instance ID, pointX, pointY].

    Set Global=Yes and you can convert your array to JSON string and save/load with local storage.

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