02-01-2024, 09:29 AM
(01-30-2024, 09:40 PM)Marcus Wrote: ... You can also look at ned.n7, tilemap_editor.n7 and ngui_theme_editor.n7 ...
In the beginning, I wanted to learn how to code GUI in the tilemap_editor.n7,
and at the end, I modified the tilemap_editor.n7 into sprite editor (simplified version) [ File : sprite_editor.zip ]
The converted sprite format is something like this one below : [ File : sprite.txt ]
Code:
[0,0,1,0,0,1,0,0],
[0,0,1,0,0,1,0,0],
[0,1,1,1,1,1,1,0],
[1,1,1,0,0,1,1,1],
[0,0,1,1,1,1,0,0],
[0,1,1,1,1,1,1,0],
[0,1,0,0,0,0,1,0],
[1,0,0,0,0,0,0,1]
Then [ File : demo.n7 ] , it is read by ImageFromMonoData function : ( note : the function which you used in denaalaafender game )
Code:
'----------------
' INITIALIZATION
'----------------
#win32
set window "Pixel Art", 1, 1, false, 10
Sprite1 = ImageFromMonoData([
[0,0,1,0,0,1,0,0],
[0,0,1,0,0,1,0,0],
[0,1,1,1,1,1,1,0],
[1,1,1,0,0,1,1,1],
[0,0,1,1,1,1,0,0],
[0,1,1,1,1,1,1,0],
[0,1,0,0,0,0,1,0],
[1,0,0,0,0,0,0,1]
])
'--------------
' MAIN PROGRAM
'--------------
set color 0, 0, 0; cls; set color 255,255,255'clear screen
draw image Sprite1,0,0
do;wait 1;until keydown(KEY_ESCAPE)'pause
'----------
' FUNCTION
'----------
function ImageFromMonoData(data)
h = sizeof(data)
w = sizeof(data[0])
img = createimage(w, h)
set image img
for y = 0 to h - 1 for x = 0 to w - 1
if data[y][x] set color 0,168, 0, 255
else set color 0, 0, 0, 0
set pixel x, y
next
set image primary
return img
endfunc
So far so good, but I am still curious, how to read the converted sprite format above directly into my sprite editor ? I know there is something missing and I am not able to strip off these symbols "[", "]",and "," from the file [ File: sprite.txt ]
Could you please help me to correct this piece of code ?
Code:
vTilemapEditor.SetMapSize(DEFAULT_MAP_WIDTH,DEFAULT_MAP_HEIGHT)
tiles = vTilemapEditor.GetTiles()
for y = 0 to vTilemapEditor.GetMapHeight() - 1
for x = 0 to vTilemapEditor.GetMapWidth() - 1
tiles[x][y].cel = int(fread(f)) - 1
next
next