02-01-2024, 01:45 PM
Quick reply here. If you change your file to:
, it becomes a valid json that you can load with JSON_FromFile if you include the json library. JSON_FromFile will return a 2D array in this case.
This code doesn't do anything, it just shows you how to get the value at x, y.
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]]
, it becomes a valid json that you can load with JSON_FromFile if you include the json library. JSON_FromFile will return a 2D array in this case.
Code:
include "json.n7"
data = JSON_FromFile("sprite.txt")
' Get width and height.
h = sizeof(data)
w = sizeof(data[0])
for y = 0 to h - 1
for x = 0 to w - 1
' Access value for x, y.
value = data[y][x]
next
next
This code doesn't do anything, it just shows you how to get the value at x, y.