-
Notifications
You must be signed in to change notification settings - Fork 1
Asset Loading
Erik Watson edited this page Apr 3, 2021
·
8 revisions
Assets can be loaded in via Bramble.assets
, each type of asset is loaded in via a dedicated function. These loading functions are essentially just Promises with some conveniences. The Image loader returns the image as a HTML Image Element, the Terrain loader builds a usable Terrain object, etc.
You will notice quite quickly from the examples that the way the assets are loaded is very similar regardless of what type of asset it is you are loading.
const { assets } = require('@erikwatson/bramble')
assets
.loadText('./path/to/text.txt')
.then(txt => console.log(txt))
.catch(err => console.error(err))
const filePaths = [
'./path/to/a.txt',
'./path/to/b.txt',
'./path/to/c.txt'
]
assets
.loadAllText(filePaths)
.then(files => {
files.forEach(txt => {
console.log(txt)
})
})
.catch(err => console.error(err))
assets
.loadImage('./path/to/img.png')
.then(img => console.log(img))
.catch(err => console.error(err))
const filePaths = [
'./path/to/a.png',
'./path/to/b.png',
'./path/to/c.png'
]
assets
.loadAllImages(filePaths)
.then(files => {
files.forEach(img => {
console.log(img)
})
})
.catch(err => console.error(err))
TODO
TODO
Terrain in Bramble is the name for the auto-tiling tile maps, they are loaded in via a JSON file that describes what image they use, what tiles exist within that image, etc.
assets
.loadTerrain('./path/to/terrain.json')
.then(terrain => console.log(terrain))
.catch(err => console.error(err))
const filePaths = [
'./path/to/a.json',
'./path/to/b.json',
'./path/to/c.json'
]
assets
.loadAllTerrain(filePaths)
.then(allTerrain => {
allTerrain.forEach(terrain => {
console.log(terrain)
})
})
.catch(err => console.error(err))
TODO