Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tilemap library - individual tiles
#1
Very much a niche bit of code, but hopefully someone may find it useful - I do.

When you have loaded the image file containing all of your tiles into the Tilemap Editor, you can see the individual cell numbers for the separate tiles by clicking on them. However, I find it useful to be able to see them all split up together, and use this code to achieve this. At times, it is even useful to grab a screen print and print off a hard copy.

Here's the code:
Code:
screen_w = 1024
screen_h = 768
'Open a window
set window "Tile numbers",screen_w,screen_h
'enable double buffering
set redraw off
t = clock()

#win32

visible img_across = 0,img_down = 0
visible img_name = ""
visible tile_w = 0,tile_h = 0
visible tile_img = ""


running = true
do

if keydown(KEY_L)
    f = openfiledialog()
    read_map(f)
    tile_img = loadimage(img_name)
   
    tile_w = width(tile_img) / img_across
    tile_h = height(tile_img) / img_down
    set image grid tile_img,img_across,img_down
endif   





'clear the screen
set color 255,255,255
cls
set color 0,0,0
x_start = 20
x_space = tile_w + 16
y_start = 150
y_space = tile_h + 20
if tile_img <> ""
   
    for i = 0 to img_across * img_down - 1
        set color 255,255,255
        draw image tile_img,x_start  ,y_start,i
        set color 0,0,0
        set caret x_start + tile_w / 2,y_start + tile_h + 4
        center i
       
        x_start = x_start +  x_space
       
        if x_start > screen_w - tile_w - 20
            x_start = 20
            y_start = y_start +  tile_h + 20
        endif
       
       
    next


set color 0,0,0
set caret screen_w/2,20
center "png name is " + img_name
set caret screen_w/2,35
center "tiles across/down - " + img_across + "/" + img_down

set caret screen_w/2,50
center "tile w/h " + tile_w + "/" + tile_h

set caret screen_w/2,65
center "width / height main png = " + width(tile_img  ) * img_across   + "/" +  height(tile_img  ) * img_down
   
   
endif   
set color 0,0,0
set caret screen_w/2,100
center "PRESS <L> TO SELECT THE TILE MAP FILE"
set caret screen_w/2,120
center "CONTAINING THE DETAILS OF THE PNG FILES TO LOAD"

'copy back buffer to the screen
redraw
'cap FPS to 60
fwait 60
until not running

'
function read_map(fl)

' Open a file.
f = openfile(fl)
if typeof(f)
    ' Read a whole line with frln.
    img_name = frln(f)
    img_across = int(fread(f))
    img_down = int(fread(f))
   
    free file f
endif
endfunc
 
All the best - Kevin.
Reply
#2
Cool... I will check it first thing in the morning... after breakfast and coffee, of course... lol
May your journey be free of incident.
Live long and prosper.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)