User Tag List

Results 1 to 4 of 4

Thread: Spawning multiple objects at random positions

  1. #1
    Clicker Fusion 2.5 (Steam)

    Join Date
    Sep 2016
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Spawning multiple objects at random positions

    Hello there.

    I am trying to spawn random objects at random positions. There's how my conditions look like.

    8153be3b83d4926a19ca3051d5f2e09b.jpg

    Firstly, I am spawning random object out of 4 monster objects that are currently on my frame. Then, I change X and Y coordinates for every monster since I do not know which one is going to be spawned. But the final result looks like this

    be16db5b22eb9d844b363b11f8b65a3d.jpg

    Monsters are being spawned only at these 2 spots. Probably there're multiple layers of these monsters, cause when I destroy one the next one is replacing it.

    Anyone has an idea what might be wrong and how to fix it properly? Thanks for your help

  2. #2
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Sumo's Avatar
    Join Date
    Jul 2008
    Posts
    642
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well first off you don't have any code to create the monsters for the "spawn bricks vertically". During each horizontal fastloop it will trigger 5 vertical fastloops. Once those vertical fastloops are done it will continue along with the rest of the code which is "Create monster, set positions, etc.".

    It also looks like you have a lot of different monster types. If they're all similar, you could add them into one "monster" using different named animations. If they're different monster movements, you can classify all your monsters under a qualifier (group) to reference them all without repeating your code for each one. Qualifiers are under the properties window when you select an active object- I believe it's the second tab from the right. Add one of the qualifiers from the popup like "Enemy". You would just have to specify which enemy you would want to create at first, the positioning would work for all the enemy types.

    I would add some variable comparison before the create monster condition to tell which monster to create. For example the green monster = 1, purple = 2, red = 3, and orange = 4. You could also add a random number generator before to randomize the placement of the monsters.

    If you want the colors to be in a specific pattern you could also write them down in some array or something and reference the array. This way you could create tons of levels quickly and easily externally. I would probably do this.


    You should set it up like this:


    +Start of Frame
    -Start loop "Spawn Bricks Horizontally" 18 times

    +On loop "Spawn Bricks Horizontally"
    -Start loop "Spawn Bricks Vertically" 5 times

    +On loop "Spawn Bricks Vertically"
    -Set counter or alterable value to Random(1,4).

    +On loop "Spawn Bricks Vertically"
    +Counter or alterable value = 1
    -Create "Green Monster" at (0,0) layer 1

    +On loop "Spawn Bricks Vertically"
    +Counter or alterable value = 2
    -Create "Purple Monster" at (0,0) layer 1

    +On loop "Spawn Bricks Vertically"
    +Counter or alterable value = 3
    -Create "Red Monster" at (0,0) layer 1

    +On loop "Spawn Bricks Vertically"
    +Counter or alterable value = 4
    -Create "Orange Monster" at (0,0) layer 1

    +On loop "Spawn Bricks Vertically"
    -Set Enemy Qualifier X position to LoopIndex("Spawn Bricks Horizontally") *70
    -Set Enemy Qualifier Y position to LoopIndex("Sawn Bricks Vertically") * 70


    If you want them to not start at the top left corner of your screen (since loop index would start out at 0) add the starting coordinates to your X and Y positions at the end since order of operations. You could put the above multiplication in parenthesis to make sure the addition doesn't affect the multiplication.


    If you added all of the monster into one active object with different animations for each monster and you just wanted it to be random with no way of choosing which monster goes where, you would only have to do:


    +Start of Frame
    -Start loop "Spawn Bricks Horizontally" 18 times

    +On loop "Spawn Bricks Horizontally"
    -Start loop "Spawn Bricks Vertically" 5 times

    +On loop "Spawn Bricks Vertically"
    -Create "Monster" at (0,0) layer 1
    -Set animation to Random(1,4)
    -Set Enemy Qualifier X position to LoopIndex("Spawn Bricks Horizontally") *70
    -Set Enemy Qualifier Y position to LoopIndex("Sawn Bricks Vertically") * 70



    You might also want to check your positioning. A loop of 18 would go through 0-17. Therefore your max position for the final monster should be X: 17*70= 1190, Y: 4*70= 280. Your "70" coefficient number should be the size of your monster if you want them to all align next to each other. Make sure you window size is big enough to view them all. You're probably creating a bunch of them off screen.

  3. #3
    Clicker Fusion 2.5 (Steam)

    Join Date
    Sep 2016
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I feel so dumb now. You;re right, I've totally forgotten about vertically loop, though I've created it.
    All the monsters were the same. The only difference was their color, so I did as you suggested and added them all as seperate animation frames.
    Now everything works as it was supposed to, thank you kindly, sir You are awesome. I hope I'd be able to help others sometime soon as well and precise as you helped me now.
    I am working on 1280x720 frame, so every monster is going to fit into screen size.

    There is another problem, though. I made a condition that upon collision with ball, monster is supposed to be destroyed. And it works only with original monster object. It does not work with any monster I've created through loops.

    8153be3b83d4926a19ca3051d5f2e09b.png

    What might the problem be?

    //EDIT

    Ok, so apparently objects I've created through "Insert Object" on frame editor cannot interact with objects created through event editor. Weird. Idk why this is happening.

  4. #4
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Sumo's Avatar
    Join Date
    Jul 2008
    Posts
    642
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hmm, the objects that you create through the event editor should still be able to interact with the other objects. Make sure the objects being created are on the same layer as the objects they are interacting with.

Similar Threads

  1. Random object spawning random y set x
    By Armiferamortalis in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 23rd December 2013, 11:47 AM
  2. Spawning Random Objects
    By Stu in forum The Games Factory 2 - Technical Support
    Replies: 5
    Last Post: 29th October 2012, 05:31 AM
  3. Moving multiple objects toward positions simultaneously
    By Blizna in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 13th November 2011, 06:56 PM
  4. random positions of active objects (square grid)
    By DEKE15 in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 4th February 2010, 09:23 PM
  5. multiple instances spawning at multiple places
    By CPW in forum Multimedia Fusion 2 - Technical Support
    Replies: 17
    Last Post: 22nd February 2009, 12:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •