Save object location to array

0 favourites
  • 11 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi guys,

        Im trying to save a bunch of object locations(x,y) to an array but I cant figure it out. Basically I have it set up to have a slot for every object being saved, and its 2 deep., one for x, one for y. But I cant figure out how to send the x,y coordinates to the array for each object? I figure on using the UID of each object(they are all the same object) to determine the slot. Can I do this?



  • This is one of those 'it depends' questions. Usually you'd use a Dictionary to use an arbitrary key/index. Here's a very quick example:


  • I see. Can I use those points to spawn objects? One of the uses Im looking for is setting up spawn points. But I want to be able to physically place them, and move them around. Then have them save location and destroy at start up to reduce the number of objects on screen. Then when the player dies, call on the saved loactions randomly.

  • Here is one way..


  • Here is one way..


    Hey man, Thanks. I think I understand how that works. Let me test it out!

  • Thanks guys. Now Im just trying to figure out a way to have them not spawn in the middle of the action. Like choose a random spawn point so many pixels away from certain objects. Im trying to use distance, but its not working out so well so far.

  • Any chance Spongehammer or mELTINGsKY has that array capx handy? Im trying to figure out how to generate random points on the layout then store those in an array which I can later loop through to spawn objects at those points / coordinates. I have a feeling the array.capx would have likely saved me a few hours of headaches by showing me the light...

    let me know & if so, thank you so much !!

  • Sounds like you're trying to do the same thing im doing mELTINGsKY -- i have the formula basically worked out i just need to know how to actually get those coordinates into an array to begin with...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • , check out latest tutorial section, there is a ton of tutorials uploaded yesterday on location and storage. Even a cool one which records the movement and allows you to rewind based on previous co-ordinates.

    The space game has spawning - have a look at that

  • Thanks DUTOIT! Ill have a look. Actually i figured out a solution to my issue by just ignoring the array entirely and basing it on normal actions.. Here is my planet spawning code:

    <img src="" border="0" />

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