0 Favourites

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

  • 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.

  • 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!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Sprite Font Generator - v3
368 112,309
RetroDaddy's avatar
RetroDaddy
Unread hot topic
86 28,711
St4rDu57's avatar
St4rDu57
Unread hot topic
99 10,137
karshinkoff's avatar
karshinkoff