Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

Check if an asset exists?

A topic by Liam Brocklehurst created Oct 06, 2016 Views: 480 Replies: 2
Viewing posts 1 to 3

I might be missing something here, but I'm just wanting to check if an asset exists (from a path) before I assign it to something.

For example, I would do something like:

    this.mySprite.setSprite("Path/To/Sprite");

but I'd like to be able to do:

    if(AssetExists("Path/To/Sprite")
        this.mySprite.setSprite("Path/To/Sprite");

You could use a simple try / catch statement like so:

try {
this.mySprite.setSprite( "Path/To/Sprite" );
} catch( error ) {
Sup.log( error ); //Something went wrong, most likely the path to the asset doesn't exist
}
(+1)

Yeah I'm thinking that's what I might have to do, thanks!