How do I pick non-duped frames from multiples of an object

0 favourites
  • 3 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hi All,

    Hoping someone may be able to help with this little problem I'm trying to solve.

    I have one object with 10 frames, each frame has a different colour box. I have 3 instances of this object on my layout and I want each object to jump to a random frame, but not duplicate. For example, Red-Green-Blue and not Red-Blue-Blue.

    I have been looking at arrays and the various tutorials and forum posts and I think that arrays are the way forward however it's not my strong point and I don't feel I fully understand them and while I can create an array of random numbers and can get the objects to pick up a number from the array, they all pick up the same number rather than a different number each. So all three objects always jump to the same frame. I had a look at the tutorial about not picking duplicate numbers but I think my struggle is actually applying the each number to an instance of the object and setting the frame number.

    Any thoughts or ideas would be greatly appreciated and if I'm being an idiot and going about it completely the wrong way, please do say so!

  • I whipped up an example for you right quick to show one solution to the problem. Essentially, you have to assign colors to sprites in turn, then check each successive sprites new color against all of the previously assigned ones for uniqueness. If it's not unique, you assign a new color to that one and do the check again. Theoretically it could get stuck in this assign/check cycle forever, but unless you have an unrealistically large amount of objects you're assigning unique colors to, there shouldn't be any issues.

    [attachment=0:2stpva0z][/attachment:2stpva0z]

    EDIT: Accidentally uploaded an old version.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey Linkman, thanks so much for showing me this, I've been playing around with it this morning and it is a great way of doing it! I wasn't even close to looking at it that way as I was convinced I needed various arrays and such, I really appreciate you taking the time to whip up the example, it's extremely helpful.

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