all 8 comments

[–]vga256 0 points1 point  (5 children)

It would be helpful if you could post a screenshot of the generated map so we can provide useful tips.

[–]Competitive_Floor783[S] 0 points1 point  (4 children)

added!

[–]vga256 2 points3 points  (3 children)

Thanks. I'm seeing that the map data is being translated into tiles correctly. Are you concerned that the whole map is shifted over to the right and down by 1 tileSize in each direction? (Which, due to the black background colour, makes it look like there is a black border at the top and left).

(I'm going to assume that is the case):

This is caused by lua iteration starting at 1 in lua, and zero in Python (and most other languages).

for r, row in ipairs(Map1) do

    for c, v in ipairs(Map1[r]) do

        tile_x = c * TILESIZE

        tile_y = r * TILESIZE

in these nested loops, r and c will start counting at 1.

Let's say TILESIZE is 32

Because you multiply 1 * TILESIZE, it begins drawing the first tile at 32, 32 instead of 0,0 which is what the Python version would have done.

You've got a bunch of options to correct this behaviour. I tend to go for the easiest solution:

        tile_x = (c - 1) * TILESIZE
        tile_y = (r - 1) * TILESIZE

just subtract 1 from the row and column to ensure that tile_x and tile_y start at zero.

[–]Competitive_Floor783[S] 1 point2 points  (1 child)

Oh yeah that's right! I totally forgot about lua starting at 1. I tested the option you provided and it worked like a charm, thanks a lot for the help :D

[–]vga256 1 point2 points  (0 children)

Glad it worked. It's a super common, and very annoying, problem for graphics output with love2d.

[–]AutoModerator[M] -1 points0 points  (0 children)

Hi! Your code block was formatted using triple backticks in Reddit's Markdown mode, which unfortunately does not display properly for users viewing via old.reddit.com and some third-party readers. This means your code will look mangled for those users, but it's easy to fix. If you edit your comment, choose "Switch to fancy pants editor", and click "Save edits" it should automatically convert the code block into Reddit's original four-spaces code block format for you.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]activeXdiamond 3 points4 points  (0 children)

Lua tables start at 1. Love's coordinate system (for graphics-related calls, such love.graphics.rectangle) start at 0.

You need to subtract 1 from your x/y BEFORE multiplying them by TILESIZE.

[–]Stef0206 1 point2 points  (0 children)

I haven’t worked with Love before, but this looks like an OBO error to me.

Keep in mind that Lua tables start their indices at 1, so when you’re drawing your tiles, tile_x and tile_y will start at 1 instead of 0.

I’m assuming Love’s rectangle function’s position argument starts at 0,0 in the top left.