Comments (4)
Thanks so much! I will give it a shot!
from starling-framework.
But the thing is that the Asset Pack contains many subfolders. (e.g "textures/page/general/nomipmap") Just like the way how AssetManager works, I wish to load all assets within a certain subfolder. (and the ability to unload it)
Ah, I see! Makes sense, and I see how this complicates things. ๐
When you call assets.enqueue(appDir.resolvePath("textures"))
, then the AssetManager simply looks at which files are available in that folder, and adds each of those files individually. Since asset packs have no way of telling you what's inside, we can't do it like that โ as you noticed.
What I'm typically doing in such situations is to add some kind of manifest
or index
file at the root of a repository (asset pack). This could be created at build time.
So the asset pack would have a file like this in its root; let's call it manifest.json
.
"files": [
"textures/page/general/nomipmap/hero.png",
"textures/page/general/nomipmap/antagonist.png",
"textures/page/specific/mipmap/bunny.png",
"..."
]
If you are able to create such a file during the build process, you could create a helper class that wraps the AssetFile object, giving you options to list what's inside or to return all files that start with a certain prefix.
That's the class that would then be used by the DataLoader to actually get the data. You could then group the assets together into multiple AssetFactories, just as you're doing now.
Again, sorry that I can't provide any source code, but I hope you get the idea. ๐
As you pointed out, I created a loader class. Is it correct?
Hm ... my guess is that this line will be a problem:
execute(onComplete, asset.readObject);
onComplete
expects a ByteArray, but readObject
tries to restore an object. So you should change it like this:
var bytes:ByteArray = new ByteArray();
asset.readBytes(bytes, 0, asset.bytesAvailable);
execute(onComplete, bytes);
(You could also just call onComplete(bytes)
โ the reason I used execute in my code is just to be on the safe side if onComplete
is null; but I don't think that can happen.)
Otherwise, I think that should work!
I hope my notes are helpful! All the best, Jimmy!
from starling-framework.
I've never used asset packs yet, so I must admit I don't have any experience with them.
However, I think it should be possible to add support for them without too much fuss. The AssetManager supports custom "DataLoader" classes. E.g., the Zipped Assets extension creates a custom data loader to provide support for zip files. This would be similar.
The idea is to create a data loader that has access to the (already loaded) Asset Packs. Instead of loading the data from a disk or an URL, as is the default, it could return it from the asset pack instead. So you'd add the assets to the AssetManager with a custom url (e.g. assets.enqueue('assetPack://hero/head.png')
). If such an URL is found by the custom DataLoader, it accesses the asset pack and returns the relevant content; otherwise, the standard loader takes over.
I know this is only a rough sketch, but perhaps it helps already? I recommend you take a look at the zip extension I mentioned above โ it should be a good starting point!
Let me know what you think of that! ๐ Of course, I'd be happy to help.
from starling-framework.
Hi, thanks so much for pointing out the direction! But the thing is that the Asset Pack contains many subfolders. (e.g "textures/page/general/nomipmap"
) Just like the way how AssetManager works, I wish to load all assets within a certain subfolder. (and the ability to unload it)
Here's the way how to currently load assets in folders:
public static function loadMultipleAsset(ass:Array,useMipMap:Boolean,autoLoad:Boolean=true,onComplete:Function=null, onError:Function=null, onProgress:Function=null):void{
var tAM:AssetManager;
for(var i:int=0,len:int=ass.length;i<len;i++){
tAM = am.getAssetManager(ass[i]);
increSubAMCount(ass[i]);
if(tAM == null){
tAM = new AssetManager(contentScaleFactor);
tAM.textureOptions.mipMapping = useMipMap;
var path:String = ass[i];
path = AssetPackManager.getAssetAbsPath(path);
tAM.enqueue(appDir.resolvePath(path));
am.enqueueSingle(tAM,path);
}
}
if(autoLoad){
if(i == 0){
onComplete();
}else{
am.loadQueue(onComplete,onError,onProgress);
}
}
}
The problem is that with Install-time Asset Packs, there's no way to get the file path so appDir.resolvePath(path)
won't find the path.
As you pointed out, I created a loader class. Is it correct?
public class InstallTimeAssetPackLoader extends DataLoader {
public function InstallTimeAssetPackLoader() {
super();
}
override public function load(url:String, onComplete:Function,
onError:Function, onProgress:Function = null):void
{
if (AssetPackManager.pad) {
var asset:AssetFile = AssetPackManager.pad.openInstallTimeAsset( url );
if (asset != null)
{
// Load some text content from the asset
// var content:String = asset.readUTFBytes( asset.bytesAvailable );
execute(onComplete, asset.readObject);
/*var components:Array = filename.split(".");
var extension:String = components.pop();
var basename:String = components.join(".");
execute(onComplete, file.content, null, basename, extension);*/
asset.close();
}else{
super.load(url, onComplete, onError, onProgress);
}
} else {
super.load(url, onComplete, onError, onProgress);
}
}
}
from starling-framework.
Related Issues (20)
- TextField AutoScale clips text if multiline and > 100% display scale HOT 2
- Glow Filter: Color issue HOT 7
- native overlay now block touch and mouse input HOT 1
- How do I use it correctly โdrawToBitmapDataโ HOT 6
- AssetManager strange behavior
- AssetManager problem HOT 9
- Reverse delay for Tween HOT 2
- Stats showing actually rendered frames HOT 8
- ArgumentError in createVertexBuffer HOT 14
- DisplayObject dispose() method doesn't automatically remove the object from its parent HOT 3
- Render Texture: "Error #3605: Sampler 0 binds an invalid texture" when not cleared or drawn before actual Image rendering HOT 3
- Render Texture: draw method doesn't render display object with filter if parent is shifted HOT 8
- Texture: Setting vertex UV coordinates doesn't take into account the potential frame of SubTextures HOT 5
- Starling Texture.fromCamera() flickering and a part of the picture is missing on Windows HOT 4
- Object not removed from Stage on Android - Starling maybe? HOT 5
- Starling update from 2.5 to 2.7 doesn't catch tap around the left/bottom side HOT 2
- Juggler: String allocation when using IAnimatable as a Dictionary key HOT 4
- OpenGL error at macOS 12.2.1 (M1) HOT 2
- [Feature Suggestion] Vector Graphic Tesselation HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from starling-framework.