Croweley Posted October 6, 2014 Share Posted October 6, 2014 Is there a way to check if a frame exists within an atlas? Preferably before setting the frame name in a sprite. Link to comment Share on other sites More sharing options...
nkholski Posted October 6, 2014 Share Posted October 6, 2014 game.cache._images[atlasName].frameData._frameNames.hasOwnProperty(frameName) Returns true or false. (atlasName = name of your atlas, frameName = frame you want to test.) clark 1 Link to comment Share on other sites More sharing options...
nemoDreamer Posted January 2, 2015 Share Posted January 2, 2015 Avoid digging into _* and internals manually.Using:game.cache.getFrameByName('characters/player.png')will return null if no frame of that name is found. clark and gauravD 2 Link to comment Share on other sites More sharing options...
Anatol Posted February 21, 2020 Share Posted February 21, 2020 (edited) Very late reply, but I was looking for a solution to the same issue. I don't think nemoDreamer's anser would work, it seems to just look for an image, not texture atlas frame. I'd also avoid using underscore as in the first reply, but you can do something with Phaser only methods like this: function hasFrameName ( { atlasName, frameName } ) { return this.state.cache.getFrameData( atlasName ).checkFrameName( frameName ) } Edited February 21, 2020 by Anatol Link to comment Share on other sites More sharing options...
Recommended Posts