Just an example,
// Project: json_types
// Created: 23-06-22
// show all errors
SetErrorMode(2)
#option_explicit
// set window properties
SetWindowTitle( "json_types" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
#constant IMAGES_JSON_FILE = "images.json"
type Vect4Type
x as integer
y as integer
z as integer
w as integer
endtype
type SpriteType
id as integer
color as Vect4Type
file as string
endtype
type ImageType
id as integer
properties as Vect4Type
sprite as SpriteType
endtype
global Images as ImageType[]
// Init (data load)
function Images_Init(images ref as ImageType[])
images.load(IMAGES_JSON_FILE)
endfunction
// Update
function Images_Render(images as ImageType[])
local i as integer
for i = 0 to images.length
Image_Render(images[i])
next i
endfunction
// Render
function Image_Render(image ref as ImageType)
if image.sprite.file <> ""
image.id = LoadImage(image.sprite.file)
image.sprite.id = CreateSprite(image.id)
else
image.sprite.id = CreateSprite(0)
endif
if image.sprite.color.w > 0
SetSPriteColor(image.sprite.id, image.sprite.color.x, image.sprite.color.y, image.sprite.color.z, image.sprite.color.w)
endif
SetSpritePosition(image.sprite.id, image.properties.x, image.properties.y)
SetSpriteSize(image.sprite.id, image.properties.z, image.properties.w)
endfunction
Images_Init(Images)
Images_Render(Images)
do
Print( ScreenFPS() )
Sync()
loop
The images.json file
[
{
"properties": {
"x": 200,
"y": 200,
"z": 250,
"w": 250
},
"sprite": {
"color": {
"x": 255,
"y": 255,
"z": 110,
"w": 150
}
}
},
{
"properties": {
"x": 300,
"y": 200,
"z": 410,
"w": 410
},
"sprite": {
"file": "bubble.png"
}
},
{
"properties": {
"x": 500,
"y": 200,
"z": 110,
"w": 110
},
"sprite": {
"file": "bubble.png",
"color": {
"x": 255,
"y": 35,
"z": 222,
"w": 250
}
}
}
]
And a zip file
Change the properties in the JSON file and run again.
http://www.nyan.cat/index.php?cat=pirate