How do I get a random sprite position

  • hi,

    i have 5 fixed sprites (all the same sprites), now i want to get the position of one random sprite of them.

    thanks

    meta

  • Hello metameta, first let me welcome you to the community!

    By coincidence i came across your post, though i find it hard to understand what precisely is your problem.

    For what i understand from your explanation is this:

    You have 1 sprite on your layout, you copied it 4 times creating 5 identical sprites on your layout.

    You want them to be placed on random locations on the layout?

    If this is not the case then please try to give a more detailed explanation of your problem, and i will try my best to help you out!

    Greetings,

    dwngrt

  • hi dwngrt,

    first part is correct - i've one sprite which i copied it 4 times = 5 same sprites. these sprites are on a fixed possition on the map

    now i want to get the location of ONE of them (random) and e.g. destroy this sprite --> 4 sprites left....

    thanks!!!!

    -meta

  • You don't need the location to destroy it

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should be able to pick a random sprite. I'm not sure whether there was a pick random but if not:

    • Generate a random number using the random function. Its max value should be the number of sprites you have in the map -1 (because of 0-index). Theres a variable for this.
    • Use the random number to get a sprite by its IID (index iD) and get its location.
    • Destroy it.
  • Hey metameta,

    Hopefully you already figured a way to accomplish your goal.

    If not: then this demo might help you a bit.

    [attachment=0:33d6eqd8][/attachment:33d6eqd8]

    Dwngrt

  • perfect! thx a lot!

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