gwinnell Posted January 31, 2014 Share Posted January 31, 2014 Hi all, Using Phaser 1.1.3, how can I get an image or "sub sprite" out of an atlas without adding it to the scene? For example, this will get me a button sprite inside the ui texture atlas, but it will add it to the scene too. var ui = this.load.atlas('ui', 'assets/ui.png', 'assets/ui.json'); // preloadvar spr = this.game.add.sprite(50, 50, 'ui', 'button_off');What I want to do is get that sprite without it adding, to use in a button. a la below, or a version of below that uses the standard string/numeric asset references. var overImg = something;var outImg = something;var downImg = something;var btn = this.game.add.button(0, 0, function() {}, this, overImg, outImg, downImg);// orthis.game.set('overImg', 'ui', 'ui/overimg'); // etc.var btn = this.game.add.button(0, 0, function() {}, this, 'overImg', 'outImg', 'downImg'); Thanks! Link to comment Share on other sites More sharing options...
rich Posted January 31, 2014 Share Posted January 31, 2014 Buttons can't use different sprites per state (up, over, down, etc), only different frames of the same atlas. If you've got all of your button states in your ui.json file then you just need to give the button a list of the frame names that correspond to the various states:button = game.add.button(100, 100, 'button', doSomething, this, 'overFrameName', 'outFrameName', 'downFrameName');If you're not sure what the frame names should be, open the ui.json file up and have a read Link to comment Share on other sites More sharing options...
gwinnell Posted February 2, 2014 Author Share Posted February 2, 2014 Absolutely brilliant, Rich -- that's exactly what I was looking for! I must have missed the 'key' parameter in the docs somehow. Link to comment Share on other sites More sharing options...
Recommended Posts