Croweley 1 Posted October 6, 2014 Report 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. Quote Link to post Share on other sites
Solution nkholski 61 Posted October 6, 2014 Solution Report 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 Quote Link to post Share on other sites
nemoDreamer 2 Posted January 2, 2015 Report 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. gauravD and clark 2 Quote Link to post Share on other sites
Anatol 0 Posted February 21, 2020 Report 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.