How do I spawn same object with unique animation frame?

0 favourites
  • 8 posts
From the Asset Store
Selection Frame
$0.25 USD
95% off
Selection frame like in RTS games, works both on mobile and desktop devices.
  • In my case I am using animation frames as a different textures for one object.

    Let's assume that my object has 15 different textures stacked in animation frames.

    What I want to do is, at the beginning of game, create 15 instances of same object but with different texture - no repeating and random.

    So, in Event editor, On start of frame Create 15 same objects, one by one, and for animation frame set Random(0,14)

    Now, random function will at some point spawn object with same textures which I want to avoid.

    What is solution for this? I was thinking: when object is created, take the number on animation frame and store it in one dimensional array. While spawning second object, use Random(0,14) for animation frame, but, check if that frame is already stored in array - if it is, run Random function again until it's different and store that animation frame number in Array. Repeat same process for the rest of instances.

    Now, this is theory, but I am new to Construct visual programming paradigm and have no clue how to make this things in Event editor.

    Please help.

  • Sounds that you need Advance random Behavior.

    I never use it but if you check manual its that you want.

    construct.net/en/make-games/manuals/construct-3/plugin-reference/advanced-random

    Look at PERMUTATION TABLES.

  • Thanks, I would like to use Arrays cuz I can use that stored values for further logic in my game.

  • OK, I am doing something very wrong

    I have spr_a with 15 different animation frames that I want to spawn 15 times, each time with different animation frame (texture in my case)

    //create first object

    System/On Start of layout:

    -Create Object spr_a

    -Set animation frame to Random(0,14)

    -Array set value at 0 to spr_a.AnimationFrame

    //create second object

    System/On Start of layout:

    -Create Object spr_a

    -Set animation frame to Random(0,14)

    SUBEVENT

    System/For "sprite" from 0 to Array.Width

    System/ spr_a.animation frame = Array.At(loopindex("sprite"))

    Set animation frame to Random(0,14)

    now the problem is I have no idea how to go back to same subevent to check again if animation frames are different, and if different to do:

    Array/Push back last spr_a.AnimationFrame on x axis

    Maybe I am doing it all wrong from very start, I need your help to figure this visual logic out.

  • Thanks for the example mrcgkh, solution looks quite interesting!

    However I manage to do this in a different way with very few steps

    On start of layout

    -create object spr_a

    -set animation frame spr_a to random (0, 15)

    Subevent

    While

    Array contains value in spr_01.animationFrame

    -set animation frame spr_a to random (0, 15)

    Trigger once

    -Array push back to Array on X axis

    So far works flawlessly!

    kudos to Ashley, Debug layout is one of the best I've seen, it's helping tremendously!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the example mrcgkh, solution looks quite interesting!

    However I manage to do this in a different way with very few steps

    On start of layout

    -create object spr_a

    -set animation frame spr_a to random (0, 15)

    Subevent

    While

    Array contains value in spr_01.animationFrame

    -set animation frame spr_a to random (0, 15)

    Trigger once

    -Array push back to Array on X axis

    So far works flawlessly!

    kudos to Ashley, Debug layout is one of the best I've seen, it's helping tremendously!

    thanks psychoanima this helped me!

  • Here is another simple way to do it - no arrays, no Advanced Random:

    ..

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