## Short article on isometric tilemaps

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
ivan
Party member
Posts: 1549
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Short article on isometric tilemaps

Check out my short article on isometric tilemaps and how to load them from a txt file:
http://2dengine.com/doc_1_3/gs_isometric.html

Notice that the example is NOT for Love2D but I made a small .love port that I'm going to attach to this post.

Txt map:

Code: Select all

                     "
"
$" !$   "                               !
$" ! #$   "                           !   #
$" ! # ) " ! # ! " & ! # ! " ! " ! # ! , " ! " ! # ! #$   "       !     " !   #
&     !     #   $" ! * # ! " ! #$   "   !           +
!   " !     #       $" ! " ! * #$   *               "
&   !           #           $" ! " ! #$                   "
!   *           +               )                   "
!                 '             !                     '
!                 #             %                     #
%                 +               $#$                 "               $#$   ,             "               $#$ # $, "$             #
(   $#$   "         &     )           #
$+$   "       ! "   !     ,     #
)     "   $" ! " ! , #$   #
!       "   $" ! * # ($ #
!         '   $" ! , # ( ! #$   *   # $# ! , #$     #   $# ! #$   #         $# ( ! #$ #           \$ #
#     (             (
#                                                     
Parsing the map file:

Code: Select all

  -- load and parse the map file
local file = love.filesystem.newFile ( "isomap.txt" )
file:open ( 'r' )
local x, y = 0, 0
local c = file:read ( 1 )
while file:eof ( ) == false do
x = x + 1
if c == '\n' then
-- new line
x = 0
y = y + 1
else
-- convert ANSI character to tile number
local tile = string.byte ( c ) - 32
if tile > 0 then
CreateSprite ( x, y, tile )
end
end
c = file:read ( 1 )
end
file:close ( )
Generating quad information from a tileset image (128 is the hard-coded tile size, this should be changed to suit your own tilemaps):

Code: Select all

  local w = tileset:getWidth ( )
local h = tileset:getHeight ( )
local cols = w / 128
local rows = h / 128
for i = 1, cols * rows, 1 do
local frame = i - 1
local x = frame % cols * 128
local y = math.floor ( frame / cols ) * 128
end
Interestingly io.open didn't work on Love2D, not sure why maybe it requires a full path or something?
To the Love2D devs: it might be a good idea for File:read to return nil whenever EOF is reached.
Attachments
isomap.love
Last edited by ivan on Tue Nov 29, 2011 6:27 am, edited 1 time in total.

tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

### Re: Short article on isometric tilemaps

Nice! That's actually a very attractive little demo you have there. Have you considered adding some controls to your demo (at the very least, ESC closes the demo?)
Kurosuke needs beta testers

ivan
Party member
Posts: 1549
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Short article on isometric tilemaps

tentus wrote:Nice! That's actually a very attractive little demo you have there. Have you considered adding some controls to your demo (at the very least, ESC closes the demo?)
Ya, thanks. I agree, it would be nice to move the camera around too, but I found that code was a bit Love2D-centric. Also the rendring technique used is not very good either.
I guess the main focus in the example is how to load tilemaps.

### Who is online

Users browsing this forum: No registered users and 39 guests