How do I Create Objects Randomly ? ? ?

  • Hey guys!!!

    How can I create multiple objects randomly?

    Example: I have 5 bubbles in five different colors and I want the colors to be created randomly.

    right now it's creaing a green bubble every "5" seconds, how can I make all the colors to be created randomly every "5" sec.

    once the "5" seconds has passed I want a green bubble and after the next 5 seconds has passed I want for example a red bubble.

    I tryed to program one of each color to be created every x second independently but it became a mess, to many bubbles were created and they were overlapping each other all the time.

    Is there a better way?

    any ideas how to solve this?

    keep it simple please I am a beginner.

    Tanks

  • Make a control object with instance var or a global var (for example color=#) and set it to a different number for each color.

    Now somewhere throw up a random number generator that constantly runs.. such as Every X seconds set instance var color to choose(0,1,2,3,4,5) or int(random((0,5)).

    Now in your spawner, sub-event down for each color:

    (main)Spawn event condition

    (sub) instance color=0 - (action) spawn blue bubble

    (sub) instance color=1 - (action) spawn red bubble

    etc

    You could also use Every tick and it will race through 0-5 but your spawn event will still grab whatever current value and use it.

    You could also use a Function that chooses and sets the color variable when called and call it in your spawning event and sub to the actual spawn event after.

  • seems a Little complicated.

    i'll try to figure it out though.

    if you could send me a capx of an idea on how to do it it would be fantastic.

    thanks alot.

  • Its not as complex as I make it sound

    I will try and work something up real quick

  • I'm new to this and it takes quite some time to understand and to get stuff done

    but i'm geting there

    Thanks alot, that would be great!

    Thanks!!!

  • See if this makes sense.

  • I think I understand!

    I'll try it out!

    Thanks for taking your time!

    Thanks alot!

  • if layout have size 500x500

    example

    every 1 sec ---> create object X or familly (in familly c2 take random object from familly)

    (

    x: round(random(0,500))

    y: round(random(0,500))

    )

  • screen example in capx http://imgur.com/a/UHBLt

  • Yes using families simplifies it greatly either way you do it.

  • Tackla

    It would be easier and less events if you just make all the bubbles one object and change the animation to set the color of the bubble if they all have the same behavior.

    Like so:

  • I didn't want to confuse him.. but yes families and putting all the "types" as animations or even frames (if static) into a single sprite would be more efficient.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks guys!

    You've all been to great help!

    Thanks alot!

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