Jump to content

Accessing particular image from a texture atlas


MadOwl
 Share

Recommended Posts

Hello!

I finally decided to try to use TexturePacker. This tool looks promising.

Now I am just rewriting tons of my code. Here's the question, I hope some of you, friends, might be able to help me:

My old code:

        var background = game.cache.getImage(backgroundName);
        something.drawImage(background, 0, 0, background.width, background.height, 0, 0, gameWidth, gameHeight);

Can I do the same thing, but with background image being placed into texture atlas which will also include multiple other images?

How can I do ' var background = game.cache.getImage(backgroundName);', but with texture atlas use? It seems methods like getFrameData return only some info strings.

Link to comment
Share on other sites

Not exactly sure what you mean, but why not just use a sprite to show the background?

// use a sprite
var background = game.add.sprite(0, 0, 'yourassetkey', 'theframename');

// and if you want, stretch it to entire game area
background.width = game.width;
background.height = game.height;

Or if the graphics should be a repeating pattern, like bricks or grass or something like that, you can use the Phaser.TileSprite class.

// use a tile sprite
var background = game.add.tileSprite(0, 0, game.width, game.height, 'yourassetkey', 'brickspattern');

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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