How do I Create a ramdom stack of individual crates (sprites

0 favourites
  • 5 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hi All,

    I'm new to Construct 2 (with a very basic amount of coding knowledge).

    I want to make an endless runner that features obstacles on the ground that you could jump on/over or smash through.

    I've been able to deconstruct the endless runner template and can figure out most things really, but I'm having some trouble figuring the obstacle thing out. I want the obstacles to be generated at random intervals (I can figure that out). I want the obstacles themselves to be random numbers of stacked individual sprites that could even be swapped out easily and have their own behavior/animations (Example: crates, boxes, cinderblocks, etc. that could each be platforms or get smashed through when player sprite overlaps). So there would be like pyramids (or maybe even some other randomly shaped) stacks of these sprites.

    Some ideas I had were to create an invisible sprite at the set random position, then have the visible crate/box sprites spawn at positions relative to that invisible sprite. Maybe the invisible sprite has to be tileable or something to create a random height for the stacks of individual sprites. Maybe these individual sprites have to be in a container or family or something.

    I really got stuck there and was hoping to get some ideas. My thought is to set things up to eventually allow for quick swapping out of sprite artwork.

    Thanks a lot in advance for any assistance or ideas you may be able to contribute.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It really depends on how you've set up the general endless runner gameplay but what you've described there is creating invisible 'spawn points' which sounds about right. You could have a 'numStacked' variable which picks a random number which relates to how many are stacked on top of each other. You could have this in an obstacle Family so you only have to set the number of stacked items once.

  • It really depends on how you've set up the general endless runner gameplay but what you've described there is creating invisible 'spawn points' which sounds about right. You could have a 'numStacked' variable which picks a random number which relates to how many are stacked on top of each other. You could have this in an obstacle Family so you only have to set the number of stacked items once.

    Well thanks for the reply. I've been brainstorming and experimenting when I get the time. The technique I'm currently using is creating a series of events for each stack that I'll later call at random intervals as functions. I'm using an invisible sprite and creating instances of the sprites in positions relative to that spawn point.

    I tried a whole lot of other stuff that wasn't working out for me, including using IID to identify and place the crate sprites. Anyway, I think this is my solution for now, but I'll see along the way if I can come up with a more elegant solution.

  • Yes that sounds good. You could put an instance variable on the spawn point and give it an integer value. If 1 > call function Stacked1, if 2 > call function Stacked2, then the functions relate to which objects are being spawned in terms of position as you described. Then every time a spawn point appears on screen give it a random number, that should randomize what is spawning. Simple enough!

  • Yes that sounds good. You could put an instance variable on the spawn point and give it an integer value. If 1 > call function Stacked1, if 2 > call function Stacked2, then the functions relate to which objects are being spawned in terms of position as you described. Then every time a spawn point appears on screen give it a random number, that should randomize what is spawning. Simple enough!

    Thanks! I just wrapped up my session wondering how best to go about randomizing that. I'll give that a shot next time

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