Jump to content

Get Atlas image without adding it to scene.


gwinnell
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...