admin管理员组

文章数量:1426479

How do I equip clothes to a sprite in Phaser? Say I use the following:

The only way I can think of is making a image with each sprite on. There must be a different way, like overlaying or something perhaps?

How do I equip clothes to a sprite in Phaser? Say I use the following:

The only way I can think of is making a image with each sprite on. There must be a different way, like overlaying or something perhaps?

Share Improve this question edited Oct 16, 2014 at 15:07 Meg 1,47212 silver badges23 bronze badges asked Oct 7, 2014 at 0:20 user3121056user3121056 3394 silver badges12 bronze badges 1
  • Wrong forum, a mod will correct that. But yes, you would overlay the "style" on the character. As long as the overlays are transparent, it would be fine. To optimize you could "cache" the character with the overlay applied. But again, wrong forum, and have no clue what Phaser is. – Evan Carslake Commented Oct 7, 2014 at 0:24
Add a ment  | 

2 Answers 2

Reset to default 5

You should check this project: https://github./makrohn/Universal-LPC-spritesheet.

And for the integration in Phaser, try Something like that:

function preload() {
    game.load.spritesheet('female_body', 'sprites/body/female/light.png', 64, 64);
    game.load.spritesheet('female_hair', 'sprites/hair/female/pixie/blonde.png', 64, 64);
    game.load.spritesheet('female_torso', 'sprites/torso/tunics/female/teal_tunic.png', 64, 64);
    game.load.spritesheet('female_legs', 'sprites/legs/pants/female/teal_pants_female.png', 64, 64);
}

function create() {
    var group = game.add.group();
    group.add(game.add.sprite(200, 200, 'female_body', 13 * 9));
    group.add(game.add.sprite(200, 200, 'female_hair', 13 * 9));
    group.add(game.add.sprite(200, 200, 'female_torso', 13 * 9));
    group.add(game.add.sprite(200, 200, 'female_legs', 13 * 9));
    group.callAll('animations.add', 'animations', 'walk', Phaser.ArrayUtils.numberArrayStep(13 * 9, 13 * 9 + 9));
    group.callAll('animations.play', 'animations', 'walk', 9, true);
}

You can use Phaser.Sprite#addChild to attach cloth sprites to your player sprite.

// Player sprite
var player = game.add.sprite(0, 0, 'player-sprite');

// Cloth sprite
var cloth = game.add.sprite(0, 0, 'cloth-sprite');

// Tweak anchor position to correctly align clothing over player 
cloth.anchor.setTo(0.5, 0.5);

player.addChild(cloth);

本文标签: javascriptSprites and equipping sprite clothes in PhaserStack Overflow