Spawn random sprites at a predetermined location

0 favourites
  • 4 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template for top-down view games)
  • Hi there, I'm fairly new to construct and I've been fascinated by it.

    I'm trying to make a small game for my son and sister's daughters. They are 3-4 years old so its gonna be a simple card game to teach them things. Such as animals, fruits..etc. Lets say I've drawn 21 fruits and have imported them in as sprites. I want to be able to show 3 of them at a time at same 3 locations on the screen. There will also be a button below, which will trigger an audio file (since they cant read) says the name of the fruit. After this point he will pick 1 of the fruits and if it's correct there will be claps & confetti (whatever) and go to the next layout (for the next question) and if its wrong, we will still remain in the same layout (till the gets it right).

    I've managed to do what I described above manually. Meaning there are 6-7 layouts and they all have the predetermined questions (eg. layout 1 asks for apple and the cards are apple, apricot, orange). Now I want to spice it up and make the questions random. Actually as I wrote this, I realized probably I wont need more than a single layout, since the questions could be spawned in the same layout, I guess?

    I searched the forums but couldnt find a thread like this. Anyone willing to help me out? Thanks in advance.

  • Lots of ways to do this:

    You can place several instances of an invisible sprite named SpawnPoint on the layout and when you need to spawn a fruit you do

    System->Pick random instance of SpawnPoint

    SpawnPoint -> Spawn Fruit

    You can make a single Fruit sprite with multiple animations (apple, pear, orange etc.)

    When you spawn or create a new Fruit, set its animation to choose("apple", "pear", "orange") - this will set random animation.

    You can then get fruit name using Fruit.AnimationName expression.

    Or you can create different sprites for different fruits and add them all into Fruits family.

    When you create/spawn Fruits family, a random family member will be created.

    Also try searching this forum and Tutorials, there should be lots of examples of such games.

  • Thanks for the reply, I was kinda busy and couldnt play around with this earlier. Now I have another problem, which is there could be doubles as the random fruits pop up. So I thought about a workaround as such:

    1) I'll have my 10 or so layout, each of which there are 3 fruits and a question button

    2) I'll try to go to these layouts randomly, so I wont have to deal with double fruits in a single layout.

    3) I have my layouts named as question1,question2,question3...question10

    4) As the correct answer is given, I want it to go to a random layout so I'm trying Go to layout (by name)

    "question",random(9) or something like that. I'm not familiar with the syntax. What should that line be

    Sorry for asking noob questions

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, you can do that.

    An easier way would be to add all 21 fruits to the layout and then delete random 18:

    And then move the remaining 3 sprites to their predetermined locations.

    There are lots of other ways how to spawn objects without duplicates, you can search this forum or tutorials.

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