Creating landscape from array

For questions about using Classic.

Post » Fri Sep 24, 2010 9:00 am

Okay, that's my current problem:

I want to draw him a column of tiles. I do this via:
[code:2hl03ttl]
FOR EACH entry in array "Array" {
IF:
value at Array.CurrentX, Array.CurrentY
THEN:
create object "GenericTile" at (LayoutWidth / 2) + (Array.CurrentX * Global('tileoffset_x')), 20 + (Array.CurrentX * Global('tileoffset_y'))
add 1 to global variable 'x_counter'
[/code:2hl03ttl]

Fine. He should have drawn a number of tiles now ... but if he doesnt stop, he will draw the next few rows also at the same position. So at the end, no matter how many columns I wanted, I will have only one column with all other columns stacked over it. So I want him to stop after the first column is done, correct the offset and continue.

[code:2hl03ttl]
IF:
'x_counter' equal to 'number_of_columns'
THEN:
substract 'substractor_x' from 'tileoffset_x
substract 'substractor_y' from 'tileoffset_y
add 1 to global variable 'number_of_columns'
}
[/code:2hl03ttl]

So the next column will be set off by the value of the substractor (usually the width of the tile). I continue this behaviour as often as needed till all columns are done. Is this wrong? It has to be, because it doesn't work.

Suggestions please?
BTW: Today is a rainy grey day. -.-
B
3
G
2
Posts: 35
Reputation: 770

Post » Fri Sep 24, 2010 10:29 am

Basically you need a simple switch here. If you go with a counter an easy way to do it is use even or odd, and two corresponding sub-events.
To start out your counter should be zero... an even number.
So before you create your first row/ column you need an event that checks the counter.
[code:30tj4v0k]if global variable 'x_counter' %(modulo) 2=0
>-create sprite at array x,y+tilewidth
>-add 1 to tilecount

if global variable 'x_counter' %(modulo) 2>0
>-create sprite at array x,y+tilewidth+ offset
>-add 1 to tilecount

if tilecount > x(the known number of tiles across)
>- set tilecount to 0
>- add 1 to global variable 'x_counter'[/code:30tj4v0k]

Course you'll probably have to add an extra event for the difference in columns, and rows offset.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri Sep 24, 2010 3:43 pm

I have to admit that I didn't quite follow the ongoing discussion between you guys and chances are I might have missed something important (looking at all that pseudo code).

But if you only want to create a flat iso terrain from an array it could be simply done like this:
http://dl.dropbox.com/u/2306601/simpleisotest.cap
Or am I missing the point?! :?
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Fri Sep 24, 2010 5:27 pm

Yeah, that's pretty good, but I'm not sure you can set up what he was wanting to do with the different tiles with that.
However you could still use the array to change the frames.

Also that brings up a bit about optimization. Depending on how big the layout is, and if you want the whole thing covered in tiles... you can actually wind up with a lot of tiles.
Too many tiles can be a big hit on performance, so one thing you could do is use a Canvas, and paste all the tiles that don't have to be used for collision detection into the canvas, and then destroy those sprites.
You could also just use the Tiled Background object as a base, and use the array to create the tiles you want different,if you want the whole screen filled that is.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests