How to load Android assets that are not compiled with the project

I'm developing a CocosSharp game for both iOS and Android and instead of precompiling all the assets (as BundledResource or AndroidAsset) I want to download them when the game starts.
This has already been implemented and saving the assets works fine.
In iOS I'm also able to use the saved assets with CCSprite for example, so for iOS it's done - great!

But in Android I can't get it to work.
I'm saving the assets to System.Environment.SpecialFolder.Personal which seems to point to the "./files" folder for the app.
The assets are saved properly and I can see them when I look at the file system.
I've also set the CCApplication.ContentRootDirectory to be the same folder that contains the assets.

But when I try to create a CCSprite with one of these assets, it stays blank.
CCApplication.Game.Content also indicates that no assets are loaded.

Does anyone have experience with the thing that I'm trying to do?
Is it even possible to load assets that are not bundled as AndroidAsset in the app?

Best Answers

Answers

  • RumarGamingRumarGaming NLMember

    Just figured out that it doesn't apply just to Android, but on iOS as well.
    I happened to have some assets left on the device from previous builds on iOS so it looked like it worked.

    Would love to get some feedback on this!

  • RumarGamingRumarGaming NLMember
    edited July 2015

    Brilliant Rami, thanks!
    That solves it for textures / sprites.

    It's still an issue with fonts for CCLabel;
    I'm using .fnt files there together with .png textures.
    I was hoping that passing a CCTexture2D to the CCLabel would solve my problems - at least for the textures, not for the .fnt file) but looking at the source of Cocos, it seems like the texture is completely ignored..

    Replacing part of the CCLabel functionality seems hard because some stuff is made internal, so I'd end up replacing a whole lot of classes.
    Maybe you have a suggestion for this as well?

    Anyway, I'm already helped a lot with just the sprite textures; I could live with bundling the fonts :-)

  • RumarGamingRumarGaming NLMember

    Thanks Kenneth, that's awesome!!
    It was the last step to making everything in my game update-able :smile:

  • PeterKrusagerPeterKrusager DKMember ✭✭

    Hey @RamiTabbara this does not work on Android anymore. Creating the CCTexture2D with a stream like this:
    var texture = new CCTexture2D (imageStream);
    will result in the application hanging. It seems to be a problem in the constructor for Texture2D. More specifically it's in the following method:
    PlatformConstruct(width, height, mipmap, format, type, shared);

    Please help me fix this since it is very limiting to have everything compiled with the application.

  • In case anyone else sees the 'hanging' @PeterKrusager described, I experienced this too. The problem appears to happen when the CCTexture2D constructor is called on the wrong thread.

Sign In or Register to comment.