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
2 Answers
Reset to default 5You 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
版权声明:本文标题:javascript - Sprites and equipping sprite clothes in Phaser - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745476872a2660002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论