在Phaser精灵和装备精灵衣服

时间:2014-10-07 00:20:45

标签: javascript phaser-framework

如何在Phaser中为精灵装备衣服?假设我使用以下内容:

http://opengameart.org/sites/default/files/human_base.png

http://opengameart.org/sites/default/files/styles/medium/public/16x18hair-clothingpack_preview2.png

我能想到的唯一方法是制作每个精灵的图像。必须有不同的方式,比如覆盖或者某些东西?

2 个答案:

答案 0 :(得分:3)

您应该检查此项目:https://github.com/makrohn/Universal-LPC-spritesheet

对于Phaser中的集成,请尝试类似的东西:



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);
};




答案 1 :(得分:0)

您可以使用Phaser.Sprite#addChild将布料精灵附加到播放器精灵。

// 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);