Jump to content

Accessing particular image from a texture atlas

Recommended Posts


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 post
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 post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...