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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
SentientPotato
Prole
Posts: 2
Joined: Thu Feb 09, 2017 8:57 am

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

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!
Attachments
main.lua Sprites to get my exact code working
tileset.png (1.6 KiB) Viewed 968 times
maptest2.lua
The map to be generated

Santos
Party member
Posts: 383
Joined: Sat Oct 22, 2011 7:37 am

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

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)


SentientPotato
Prole
Posts: 2
Joined: Thu Feb 09, 2017 8:57 am

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

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.

### Who is online

Users browsing this forum: No registered users and 43 guests