How do I spawn an object in either location A or location B?

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.
  • How could I get an object to spawn in either location "A" or "B"?

    Location A

    X - 400~600 and Y - 300~500

    Location B

    X - 100~300 and Y - 1000~1100

  • Set a local variable to choose(1,2) and if 1 spawn at location A and if 2 spawn at location B.

  • Can you elaborate on this a little bit more, please?

    (So basically I have when sprite1 gets destroyed I want sprite2 to spawn in a random location (location A or B))

    Should I make an event saying "Sprite1 On Destroyed" ...and then what?

  • Also, could I set it up to pick 4 or 5 locations?

  • On sprite destroyed, sub event, add a local variable and set variable to choose(1,2), sub event again, if variable = 1, spawn sprite2 at location 1 etc

    If you want more locations then you choose from more numbers and create more sub events.

  • mbuckenmeyer90 - That would look something like the image below.

    When "Locations" equals 1 or 2, I have the System Creating Sprite2 at random locations within the X & Y coordinates.

    If the same variable equals 2 or 3. I have the System create Sprite2 at specifically chosen locations on the X & Y.

    Finally if the Locations variable equals 5. I have system create Sprite 2, at somewhat random locations on X & Y, using "choose"

    There are many ways you could accomplish this. This just shows one way, using randomly chosen coordinates, specifically chosen, or choosing randomly from a few choices for each the X and the Y location.

  • Thanks for the help, I really appreciate it.

    But now I have two additional questions. What If I decided I wanted multiple copies of Sprite2 being created. IE, have 1-5 copies of Sprite2 being created.

    Also, does it matter if I use a Local Variable or a Global Variable?

  • If it's predetermined you can duplicate the create object action. If not you can use a for loop 1 to x where x is a local variable set to 1-5. LV or GV no not really I guess.

  • Thanks for the help, I really appreciate it.

    But now I have two additional questions. What If I decided I wanted multiple copies of Sprite2 being created. IE, have 1-5 copies of Sprite2 being created.

    Also, does it matter if I use a Local Variable or a Global Variable?

    I'm honestly a bit lost, didn't I answer that in the screenshot? Do you mean, that you have 1-5 different versions of Sprite2, to randomly be chosen from? That could handled in a bunch of different ways.

    If it's a still frame sprite, with no animations. Creating a Sprite Object with multiple frames, with animation speed to 0, and no loop. Then set another variable to a random(0-4), For Each Sprite2 on Creation. And, call that variable for the random frame, at the creation For Each Frame for the Sprite 2 Objects.

    If they are 5 separate Sprite Objects(i.e. Sprite2, Sprite3, Sprite4. Sprite5, Sprite6), then that could be done similarly. But, set another variable to set to one of the 5 Object Names. If they all act similarly, this would be done easily using a Family Object. Then setting random variable, 2-6, and then using "Create Object (By Name)" Action. Object name field would look something like ("Sprite" & RandomNumberHere) without the parenthesis. That is, if "RandomNumberHere" was the name of the variable set before hand. And each Sprite Object is named "Sprite2", "Sprite3", "Sprite4". "Sprite5", "Sprite6".

    It depends on what you are looking to accomplish exactly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I apologize if I am not understanding something, I am still very new to this.

    brainwavecreations, perhaps I misunderstood your screenshot? But to my understanding, you're screenshot shows how I could create one copy/instance of Sprite2 in 5 different locations. But then I was curious how I would create more than one copy/instance of Sprite2. Sprite2 being a single frame / no animation.

    Reading your second reply, it sounds to fit your second paragraph. I think I understand. My biggest issue would be that I am not sure how I would 'call for a frame" from the animation from Sprite2.

    If I were to use that method using an animation, I don't think I would want it to be random. Otherwise, wouldn't it likely create 1-5 copies and they could look different (since the frames in the animation would be different)

    Again I apologize if I am just not understanding, and I am sorry if I confused you more.

  • FYI, to anybody that comes to this forum, this conversation was later continued on another question forum I posted "HOW DO I SPAWN MULTIPLE COPIES OF A SPRITE?"

    construct.net/en/forum/construct-3/how-do-i-8/spawn-multiple-copies-sprite-170924

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