Author Topic: Not mapping tiles correctly (Python/Libtcod 1.5.1)  (Read 12310 times)

MisterMoxxie

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Not mapping tiles correctly (Python/Libtcod 1.5.1)
« on: May 28, 2014, 04:11:20 AM »
Hello!

I'm working on mapping my custom 'tile' font for use in Libtcod 1.5.1 with Python. I've set up a rendering test to make sure that I've mapped the font correctly, and that I know the corresponding ID numbers for my 'tiles'. In libtcod, you can not specify seperate tile sizes. Since it's mapped with the font, all the characters have to be the same. However I want 32x32 tiles, and 16x16 font. The obvious workaround, was to just map 4 16x16 tiles for each 32x32, and render them that way.

It's been working well so far, save one strange issue. For some reason, it does not seem to be recognizing all of the 32x32 wall tile, only the bottom-right corner. You can see in my render test, the highlighted area is where I think the wall tiles should be. I actually placed a second 32x32 wall tile right next to the first, to see if it would render that way.

Here's my source, as well as links to my 'font' file, the render test, and the specific documentation for this process in LibTCOD. Thanks for taking the time to help me out!

Mapping the Font
Code: [Select]
#small tiles
libtcod.console_map_ascii_codes_to_font(256, 1, 0, 5)  #map all characters in 1st row
libtcod.console_map_ascii_codes_to_font(257, 3, 0, 6)
libtcod.console_map_ascii_codes_to_font(260, 2, 0, 7)  # ...
libtcod.console_map_ascii_codes_to_font(262, 1, 0, 8)
libtcod.console_map_ascii_codes_to_font(263, 1, 0, 9)  #map all characters in 5th row

#large tiles
libtcod.console_map_ascii_codes_to_font(264, 8, 0, 10)  #map all characters in 6th row
libtcod.console_map_ascii_codes_to_font(272, 8, 0, 11)
libtcod.console_map_ascii_codes_to_font(280, 6, 0, 12)
libtcod.console_map_ascii_codes_to_font(286, 6, 0, 13)
libtcod.console_map_ascii_codes_to_font(292, 4, 0, 14)
libtcod.console_map_ascii_codes_to_font(296, 4, 0, 15)  # ...
libtcod.console_map_ascii_codes_to_font(300, 2, 0, 16)
libtcod.console_map_ascii_codes_to_font(302, 2, 0, 17)
libtcod.console_map_ascii_codes_to_font(304, 2, 0, 18)
libtcod.console_map_ascii_codes_to_font(306, 2, 0, 19)  #map all characters in 15th row

Rendering Test
Code: [Select]
n = 160

for x in range (3, 67, 7):
    for y in xrange(2,46,2):
        libtcod.console_put_char_ex(window, x, y, n, libtcod.white, libtcod.black)
        libtcod.console_print(window, x+1, y, ':' + str(n))
        n = n + 1

Documentation : http://doryen.eptalys.net/data/libtcod/doc/1.5.1/html2/console_set_custom_font.html?py=true
Render Test : http://oi61.tinypic.com/11rgpax.jpg
Font Image : http://oi57.tinypic.com/fnaanr.jpg (Yes, the background is actually transparent. It just got changed when it was uploaded.

Aukustus

  • Rogueliker
  • ***
  • Posts: 440
  • Karma: +0/-0
    • View Profile
    • The Temple of Torment
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #1 on: May 28, 2014, 09:51:00 AM »
Are you having trouble with some of the tiles being rendered white or is that just intentional? Since there's a simple fix for that.

MisterMoxxie

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #2 on: May 28, 2014, 05:51:39 PM »
For some reason, it does not seem to be recognizing all of the 32x32 wall tile, only the bottom-right corner. You can see in my render test, the highlighted area is where I think the wall tiles should be. I actually placed a second 32x32 wall tile right next to the first, to see if it would render that way

Aukustus

  • Rogueliker
  • ***
  • Posts: 440
  • Karma: +0/-0
    • View Profile
    • The Temple of Torment
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #3 on: May 28, 2014, 08:07:39 PM »
Well, test putting a single green pixel to each tile that doesn't show and test if it works.

MisterMoxxie

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #4 on: May 28, 2014, 08:15:44 PM »
Ill definitely try that when I get home. Its just strange that it reads the 16x16 fine, but not the 32x32 of the same tile.

Aukustus

  • Rogueliker
  • ***
  • Posts: 440
  • Karma: +0/-0
    • View Profile
    • The Temple of Torment
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #5 on: May 28, 2014, 08:22:38 PM »
Yeah, that's definitely weird. I mean that libtcod generally when it reads a font file it checks if the tiles are colored or something. The basic idea is that each tile needs to have at least one pixel thats R,G,B values are R != G != B. That should fix the tiles being rendered white, but I have no idea why it works with the 16x16 size but not with the 32x32.

MisterMoxxie

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #6 on: May 28, 2014, 09:16:19 PM »
And what makes it even more strange is that on both of the 32x32 wall tiles (I put two in to see if that spot just wasn't rendering correctly) it reads the bottom-right corner but the other three show up white.

Aukustus

  • Rogueliker
  • ***
  • Posts: 440
  • Karma: +0/-0
    • View Profile
    • The Temple of Torment
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #7 on: May 28, 2014, 09:40:34 PM »
I guess that the second value of these "libtcod.console_map_ascii_codes_to_font(292, 4, 0, 14)" and so on should be the maximum value of tiles cabable of being in the font row, not the amount of tiles you have there made. Try putting 32 there and do some work with the numbers.

I'm not sure if it will help but I think putting 32 there and mapping whole rows of font file can be helpful at least when the number of tiles increase.

Edit: You should basically map whole rows I think as I've done with my game:

Code: [Select]
    libtcod.console_map_ascii_codes_to_font(160, 32, 0, 2)
    libtcod.console_map_ascii_codes_to_font(192, 32, 0, 3)
    libtcod.console_map_ascii_codes_to_font(224, 32, 0, 4)
    libtcod.console_map_ascii_codes_to_font(256, 32, 0, 5)
    .
    .
    .
    libtcod.console_map_ascii_codes_to_font(256+32+32+32+32+32+32, 32, 0, 11)
« Last Edit: May 28, 2014, 09:50:18 PM by Aukustus »

MisterMoxxie

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Re: Not mapping tiles correctly (Python/Libtcod 1.5.1)
« Reply #8 on: May 28, 2014, 10:00:01 PM »
No, that's how it was before and I had the same issues. That specific font layout and mapping is set up for use like this, where you don't map every character in the font. The only thing that did was give me a lot of empty ascii codes.