How do I spawn trees, rocks, and other resources randomly?

0 favourites
  • 5 posts
From the Asset Store
Rock Anthems music pack is a collection of 12 rock music tracks and 12 looped versions.
  • Hi, something I've been wondering how to do ever since my Construct 2 days is spawning resources in a random place. I'm wanting to create a top down survival game but every time I've tried before, I have always gotten stuck on this. I have tried every way I can think of but none of them are really that good so I'm looking for anybody who might have good way of doing this. I just need them to spawn in random places, respawning I can handle :)

    I would class myself as having an intermediate level of knowledge for the engine. I know quite a bit but I'm no expert so please try and explain in the best way possible :')

    Thank you!

  • If it's a random location then you can choose between a range of x,y and place it.

    If it's set locations but the items are random you could add the resources to an array and assign them as variables to location sprites.

    There are loads of ways it just depends how the game works. I can't really imagine your game but randomness is easy enough to do.

  • If it's a random location then you can choose between a range of x,y and place it.

    If it's set locations but the items are random you could add the resources to an array and assign them as variables to location sprites.

    There are loads of ways it just depends how the game works. I can't really imagine your game but randomness is easy enough to do.

    I remember once trying the range of x and y, but some were spawning half in the map and half outside. Do you know how I would stop that from happening. I think I might have an idea but not 100% sure. If my sprite is say 96x128 would I make it so on start of layout, spawn object tree at random tree.width, 1920-tree.width for X and tree.height, 1080 - tree.height for Y or am I nowhere near XD

    Thanks for your response :)

  • I just meant spawn a tree at x = random(0,800) y = random(0,800) if 0 and 800 are the size limits of the layout, in its simplest form. It would pick a random value for x and y i.e. spawn tree at 43,290. It really depends on what you are trying to achieve.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I just meant spawn a tree at x = random(0,800) y = random(0,800) if 0 and 800 are the size limits of the layout, in its simplest form. It would pick a random value for x and y i.e. spawn tree at 43,290. It really depends on what you are trying to achieve.

    Yeah I understand that part, I think I have a solution, if i just give leeway for the resources height and width so that it doesn't spawn anywhere near the layout's borders. Thank you plinkie :)

    I think i should probably learn some more about arrays too, that's another thing i've never quite figured out :)

    - If anyone else has any ideas, they're appreciated as there might still be a better way :')

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