Page 1 of 1

Problem with "Tutorial:Efficient Tile-based Scrolling" Tutorial

Posted: Thu Feb 09, 2017 9:28 am
by SentientPotato
I've gone and done this: https://love2d.org/wiki/Tutorial:Effici ... _Scrolling

Fast forward and I've added to the code a bit. One change I've done is have it interpret a one-dimensional array: instead of map[x][y], it's map[1,2,etc.]

My problem is, it doesn't display the first row and the last column of tiles. So instead of showing a 20x20 grid, it displays 19x19. I've tested out the original code from the tutorial and it has essentially the same issue(doesn't display last row/column.) If there's any input I can get as to what the problem is, I'd appreciate it.

I have included the project files.

Thanks!

Re: Problem with "Tutorial:Efficient Tile-based Scrolling" Tutorial

Posted: Sat Feb 11, 2017 12:42 pm
by Santos
Hi SentientPotato,

Try changing:

Code: Select all

map_x = math.max(math.min(map_x + dx, map_w - map_display_w), 1)
map_y = math.max(math.min(map_y + dy, map_h - map_display_h), 1)

to (note the "+ 1"s)

Code: Select all

map_x = math.max(math.min(map_x + dx, map_w - map_display_w + 1), 1)
map_y = math.max(math.min(map_y + dy, map_h - map_display_h + 1), 1)

and:

Code: Select all

tilesetBatch:add(tileQuads[map[(x + (y+math.floor(map_y)) * map_w)+ math.floor(map_x)]], x*tileSize, y*tileSize)

to (note the "- 1"):

Code: Select all

tilesetBatch:add(tileQuads[map[(x + (y+math.floor(map_y - 1)) * map_w)+ math.floor(map_x)]], x*tileSize, y*tileSize)

Re: Problem with "Tutorial:Efficient Tile-based Scrolling" Tutorial

Posted: Sat Feb 11, 2017 8:15 pm
by SentientPotato
Thank you, Santos!

I implemented your suggested changes, and it works! I knew it had to be something simple, I just couldn't wrap my head around what exactly was missing.