How do I Loop a Randomly Generated Terrain (Not Background)

0 favourites
  • 7 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hi, everyone!

    So I've got 3,601 specific numbers which I store in an array to determine the Height/elevation of the ground.

    On runtime I do:

    For each "x" in (GroundArray)element i Create Object (Sprite 1x300) to cover the ground

    Everything seems to be working fine, except i'm not sure how to scroll loop the ground so that when i reach my layout width the first data comes full circle.

    What I am trying to achieve: I am trying to do a 480x640 moon lander-side(that goes left and right) scrolling game with infinite looping kind of game.

    Any advice?

    Thanks!

  • When your scroll value reaches your array width reset the count of the array.

  • When your scroll value reaches your array width reset the count of the array.

    Hi newt!

    Thanks for the quick reply!

    At first I thought, if I could just plot all of the 3,601 numbers into a single layer say "terrain", I would be able to treat that layer as as single object much like a "tilebackground" where one can just reset x to a value (as you say-when my scroll value reaches the array width). I also thought about putting the ground_sprite in as a family, but really there is only one sprite before run-time so I dont think it was a viable solution. I still couldn't seem to find a way to reference them as one entity.

    Also, as you might have already guessed, the cpu is rid high when i initially start the game and move my platformer, so any more suggestion on how to plot these numbers and treat them as one would be a treat.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would suggest destroying any sprites you no longer need.

  • To make it one object you can either use a tilemap or use a paster/canvas object.

    You can draw the terrain to the canvas or paster object, so you'd have only one object. It doesn't do anything for collisions though.

    With a tilemap you just set the tiles with events and you get collisions no problem.

    As far as wrapping you'll not want a single object.

    With just sprites as you have you could do this:

    sprite: x < viewportLeft

    --- sprite: set x to self.x + layoutWidth

    You could also reduce the number of objects to one's on screen and just update them from the array as the player moves.

  • I'll talk about the looping instead of how to optimize it performance-wise (generating chunks with canvas or paster is a good idea, you will end up with about two big sprites that you will move at the bottom at any time).

    If you wanna know the height value at a specific x, you can look up:

    height = array.at(xvalue%array.width)

    So if you wanna know the height at x = 4000, you will end up looking in the array at 399. The operation is called modulo.

  • Great!^^

    I just looked them up. When using Paster is there anyway to set xy coordinates?

    like:

    GroundPaster: Paste Object "GroundSprite" into canvas (GroundYArray.CurX,GroundYArray.CurValue)

    Currently this is what I have to plot the ground.

    Layout&Width Size=480,640

    GroundYArray: Set width =55(for this example)

    ---
    GroundYArray: for each x element
    { 
    GroundYArray: Set value at GroundYArray.CurX to tokenat("21,21,22,23,24,25,29,30,33,37,40,41,43,45,47,48,49,49,50,50,50,50,50,50,50,50,50,49,49,48,48,48,47,46,46,45,45,43,42,41,41,41,41,40,40,39,39,39,38,38,38,38,38,38,37,37(and so on)", GroundYArray.CurX, ",")
    
    (Disabled to try paster)
    Create Object GroundSprite on layer 0 at (GroundYArray.CurX,(LayoutWidth+100)-int(GroundArray.CurValue))
    } 
    ---[/code:8xtzin9a]
    I've been thinking, is it possible to just draw a single line creating a single object connecting the GroundYArray instead?? Thanks!
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)