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

Get help using Construct 2

Post » Thu Feb 04, 2016 3:07 am

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!
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Thu Feb 04, 2016 3:27 am

When your scroll value reaches your array width reset the count of the array.
Image ImageImage
B
166
S
49
G
154
Posts: 8,099
Reputation: 100,219

Post » Thu Feb 04, 2016 7:28 am

newt wrote: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. :)
B
15
S
7
G
34
Posts: 55
Reputation: 18,478

Post » Thu Feb 04, 2016 3:38 pm

I would suggest destroying any sprites you no longer need.
Image ImageImage
B
166
S
49
G
154
Posts: 8,099
Reputation: 100,219

Post » Thu Feb 04, 2016 6:31 pm

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.
B
89
S
30
G
95
Posts: 5,154
Reputation: 63,444

Post » Thu Feb 04, 2016 6:44 pm

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.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri Feb 05, 2016 1:49 am

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)
Code: Select all
---
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))
}
---

I've been thinking, is it possible to just draw a single line creating a single object connecting the GroundYArray instead?? Thanks!
B
15
S
7
G
34
Posts: 55
Reputation: 18,478


Return to How do I....?

Who is online

Users browsing this forum: Artpunk, Cool Gamez, marcoscodas and 12 guests