Closed Hazurl closed 6 years ago
because the key 'sprites' is the only one that store an array
it doesnt have to use an array technically. we could do something like:
"hello.png" : {
"filepath" : "assets/hello.png"
"pos" : [0, 0],
"scale" : {
"type" : "percentage", # "pixels"
"scale" : [2, 2]
}
}
I prefer to make an array, as you don't want to collide with background
nor music
keys, and you probably want to loop through only the sprites...
for the love of consistency hazurl
so you want :
self.assets = {
'music' : music_name,
'bacground' : backgournd_name,
'tree' : { 'file' : 'assets/tree.png', 'position' : (10, 10), 'scale' : 2},
'player' : { 'file' : 'assets/player.png', 'position' : (100, 10), 'scale' : 1},
'farmer' : { 'file' : 'assets/farmer.png', 'position' : (200, 10), 'scale' : 1}
}
instead of
self.assets = {
'music' : music_name,
'bacground' : backgournd_name,
'sprites' : [
{ 'file' : 'assets/tree.png', 'position' : (10, 10), 'scale' : 2},
{ 'file' : 'assets/player.png', 'position' : (100, 10), 'scale' : 1},
{ 'file' : 'assets/farmer.png', 'position' : (200, 10), 'scale' : 1},
]
}
?
more like:
self.assets = {
'music' : {
"ambience" : {"file" : "music/bg1.wav", "loop" : false}
},
'bacground' : {
"bg1" : {"file" : "bg/bg1.jpg", "style" : "stretched"},
"bg2" : {"file" : "bg/bg2.jpg", "style" : "centered"},
},
'sprites' : {
"tree" : { 'file' : 'assets/tree.png', 'position' : (10, 10), 'scale' : 2},
"player" : { 'file' : 'assets/player.png', 'position' : (100, 10), 'scale' : 1},
"farmer" : { 'file' : 'assets/farmer.png', 'position' : (200, 10), 'scale' : 1},
}
}
forgot to clarify but basically, imagine we create some kind of asset manager so that we can cache certain assets instead of unloading and reloading every scene. this is how youd prefetch them then you can just reference them like self.assets.backgrounds["bg1"]
anywhere in the game.
1) 2 backgrounds ? 2) why a dictionnary on 'music' and 'background', there is only one value for each, atleast that how the json is. 3) if you use the 'file' key in key of your cache you can recover the sprite without loading it every scene. 4) we could use a dictionary in 'sprites' instead of an array, but where do you get that key ? json_doc::assets As you can see the json is an array, all I do is reflect the json.
Still a lot to talk about...
why not make it a default dict and leave it empty