Create random sprites in specific positions

  • I have a family with 5 sprites and I need to create each sprite in the screen randomly, in specific positions. What's the right method to do this? Could someone give me tips. I bought Construct2 to learn about the logic process. Thanks.

  • you can have a hidden sprite then at start of layout or whenever you want your random sprite to appear put a System>create object action have x be = to hiddenspitename.x and y =hiddensprite.y to create the family at the hidden sprite

  • volkiller730

    So I need to create 5 invisible sprites for each sprite's family that I want to show?

  • no if you mean for each family member (1familygroup) you say create familyname like i said and it will randomly spawn a object thats in that family

    but if u mean like you have 5 different familys you could use instance variables on the hiddenoject to choose the family you want to create the might be a better way for this one but i cant think of any

  • Sorry. I think I was not clear enough. I've a one family with 5 sprites and I need to show all the family members in the screen (5), in different positions at the beginning of each game. The player must put the 5 sprites in order.

  • This should be what you're after. Bit messy, but it will get you out of trouble. I'm sure you can clean it up, because if I did it, you'd not learn anything <img src="smileys/smiley36.gif" border="0" align="middle" />

    dl.dropboxusercontent.com/u/108799982/Capx%20Demos/RandomSprite.capx

  • Thanks emoaeden for the capx but could you save it in r146 version, please?

  • Sorry, to my knowledge you can't save a previous version. You can either update, or just install r147 in a seperate directory, just so you can get the code.

    I recomend running r147, unless you are using WebGL

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you. I understood your solution very well.

    I was giving up and using frames rather than families. The only difference in this example is that I want to swap sprites instead of dragging them to the right place.

  • I've only two questions about this solution:

    • how can I do to prevent the correct order be randomly selected?
    • if I need to use more than one family, containing other members, I'll have to create a process for each one? When I used frames, I can identify which of them would be in each location. Could I control or identify the order of the families members?

    Thanks

  • If emoaeden can not answer these questions, could someone do this?

  • can someone post for 146 version..please

  • You could tell the code that the first X can not have number 1 for example, to ensure it's never easy.

    If you want to use frames, then you can use very similar code, instead of using family references, just use frame references, shouldn't be too hard.

    Let me have a go, and see what I can do.

  • dl.dropboxusercontent.com/u/108799982/Capx%20Demos/RandomSprite1.capx

    That's what I came up with, there is an issue with the swapping of the second number to the firsts position, but I'm sure you'll be able to fix it. If not, someone else on the forum can give it a shot.

  • Thank you,

    I've created the swap code. The idea to prevent that one of the cards do not occupy their home during the draw is interesting, but I think it will be best to prevent that they all stay in the correct formation. Is it possible? Regarding the use of families, from what I understand we cannot identify the members positions (order), right?

    Any difference between using families and animations in the game performance? I know how to adapt the code to use frames and I think it would be better because I'll have more control. What do you think?

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