Jump to content

Animating each part of the group


Recommended Posts

Hello, just new to phaser and i was looking at the examples on the phaser site.


i want to do something like this :


i have a character and he can be upgraded.


for example, the character has a pistol for weapon initially. but then he can have a rifle later on. or his head does not have helmet but he can have later on.


i'm thinking i can have different spritesheets for each part of the character.


one spritesheet for the head,  one for body, for weapon, etc.


and then combine them all into one main sprite.


i saw on the example this : http://phaser.io/examples/v2/groups/group-transform


it looks a bit like what i want to do but not quite.  mainly, i want each part to contain its own animation.. like maybe the head, it's eyes is moving.


and also.  how to animate that robot. like,  if i press the arrow, it will look like it is walking..


not sure if i epxlained it right so you can go ahead and ask me questions.


looking forward to your help.



tldr : how can i do this - i have a character that can change his appearance..mainly, he can have diff. weapon or headgear, or even clothes.. if you played ragnarok online, i think you know what i mean. 



Link to comment
Share on other sites

Many questions :) Lets break it down.


1. Adding and Removing Equipment.


You can have a sprite added as a child onto another sprite so it looks like its being added on. I prefer this to the spritesheet method and swapping out styles, but that's just me.


//To start you make the sprite like so.

this.sprite = this.game.add.sprite(x,y, 'GUNZERKER');


//Add a Child

this.rifle = this.game.add.sprite(x, y, 'quadrupleRifle');



//Then position as required

this.rifle.x = x;

this.rifle.y = y;

this.rifle.width = width;

this.rifle.height = height;


2. How to animate.


Rather than typing it all out, check out the standard tutorial, which can explain it better :)

//Part 1 for the beginning of it



//Part 4 has the bit you need, but you should go through all of it.



Hope that helps!

Link to comment
Share on other sites


  • Recently Browsing   0 members

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