Jump to content

add sprites to character


ikwileten12
 Share

Recommended Posts

Hello

 

I have been looking around for ages trying to get this to work but have not been able to find anything.

so i decided to put up a post.

basically i am trying to make my character wear a weapon. much like they do it in terraria where the weapon is connected to his hand and tweens downwards.

 

example: 

http://prntscr.com/5if72i

 

I hope this is enough info.

 

thanks!

Link to comment
Share on other sites

var weapon = this.game.add.sprite(0, 50, "weapon");

weapon.anchor.set(0, 1);

playersprite.addChild(weapon);

 

the "magic numbers" (for the position and the anchor point) of course depend on the size and orientation of the weapon sprite and the size of the player sprite and the position of the players hand.

 

the position of the spirte (0, 50) is relative to the upper left corner of the player sprite. so try to find the hand :)

 

the anchor for the weapon determines around which point it rotates (that should be the handle) the values are given as a fraction of the weaponsprite size.

 

with addchild the weapon always sticks to the player, and also get's the players scale, rotation and everything.

 

You can then rotate the weapon sprite and it will look like a swing.

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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