Shuffle behaviour

0 favourites
  • 5 posts
  • It would be nice if there was a Shuffle behavior, where I could make a container (held by some background component or something), assign various sprites to it and then tell the container (or the parent object that has the container [if I understand how containers work]) to shuffle the positions of the items held (it would be a Shuffle behavior on the parent I think if it only holds one container [is it a property?] at a time)

    I'd like to be able to set a time interval for the auto-shuffle (and be able to set that to 0 to stop shuffling) and also to be able to manually tell it to shuffle the item locations

    this is very handy for memory games (e.g. where you have a grid of turned-over cards and you want to find pairs - they need to be shuffled at the beginning and possibly also periodically for making it harder)

    not sure if there is such behavior already and I guess I need to learn the Javascript API (or can I make behaviors using eventsheets?) to implement it myself (is there any example of how to make a new behavior)?

  • that's not quite how containers work.

    shuffle is not too difficult to program with events. do some research on it. search the forums/tutorials. I'm sure you'll find something.

    Also, I suspect there is already a 3rd party plugin that does this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • regarding Containers, the doc I see here: scirra.com/manual/150/containers seems to say that each object has a Container property, to which I can link more objects.

    So I could have a background object that in its Container holds multiple cards

    I want to have a Behavior that shuffles the locations of the linked items (not of the parent item that has the Container property), with a property to do it in a time interval and also be able to invoke the behavior on-demand.

    Of course, if there is no API currently to enumerate items in a container, it would be nice to have that, since one could use Containers for more stuff then (like for making logical graphs). In fact containers could have an option on whether they treat all objects as one (as they do now), or if they're just a logical grouping (used in EventSheets by enumerating linked objects or used by behaviors)

    a related question btw is, can I make a Behavior using eventsheets or do I have to use the Javascript API?

    btw, what I found on the forums was code to shuffle arrays, don't want to do that, want to have the simplest way to shuffle objects around in the layout (this is more of a design goal, to make a reusable thing for such games, I know myself how to shuffle stuff in code)

  • containers don't have a parent object. there's no hierarchy involved. they're just all in it together. anything that happens to one, happens to them all.

    shuffling their positions and shuffling with arrays is really not any different.

    put the positions in the array. shuffle it. set the cards using the shuffled array.

  • if I could link array cells to properties of sprites (like databinding), then it would be the same, but I don't think I can. I don't want to use code to relocate the objects, neither I want to use code to shuffle the array (does it have such method on its own btw?)

    also, I just checked and indeed if I add two sprites and edit the first one's container property to add the 2nd one, then the property inspector shows the container property of the 2nd sprite also to contain the 1st one (they share the same container instance).

    But this is fine, it just means that I would like to have Behaviors attached ONTO CONTAINERS. That could be used for other scenario too, not just for shuffling the locations of visual objects they contain

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