Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NGUI examples
#7
(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 ]  Big Grin Big Grin Big Grin

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 ?  Big Grin  
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


Attached Files
.n7   demo.n7 (Size: 861 bytes / Downloads: 3)
.txt   sprite.txt (Size: 159 bytes / Downloads: 6)
.zip   sprite_editor.zip (Size: 5.4 KB / Downloads: 4)
Reply


Messages In This Thread
NGUI examples - by Marcus - 01-21-2024, 03:15 PM
RE: NGUI examples - by kevin - 01-21-2024, 05:07 PM
RE: NGUI examples - by 1micha.elok - 01-30-2024, 03:46 AM
RE: NGUI examples - by Marcus - 01-30-2024, 09:40 PM
RE: NGUI examples - by 1micha.elok - 02-01-2024, 09:29 AM
RE: NGUI examples - by kevin - 01-31-2024, 02:32 PM
RE: NGUI examples - by Marcus - 01-31-2024, 04:11 PM
RE: NGUI examples - by Marcus - 02-01-2024, 01:45 PM
RE: NGUI examples - by 1micha.elok - 02-05-2024, 09:09 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)