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
Before you make a thread asking for help, read this.
Post Reply
SentientPotato
Prole
Posts: 2
Joined: Thu Feb 09, 2017 8:57 am

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

Post by SentientPotato » Thu Feb 09, 2017 9:28 am

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
(2.55 KiB) Downloaded 28 times
tileset.png
Sprites to get my exact code working
tileset.png (1.6 KiB) Viewed 967 times
maptest2.lua
The map to be generated
(1.3 KiB) Downloaded 26 times

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

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

Post by Santos » Sat Feb 11, 2017 12:42 pm

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

Post by SentientPotato » Sat Feb 11, 2017 8:15 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests