attach weapons to sprites in runtime?

I’ve never used welded joints so I’ll differ to Brent on this one.

There is a problem now…

How do i keep up the rotation of the gun with the rotation of the hand???

Thanks again!

Hi @coolromin,

Weld joints are easy: just weld the two objects together at a point in world coordinates. This would likely be the player’s hand or arm, in your situation.

[lua]

physics.newJoint( “weld”, object1, object2, anchorX, anchorY )

[/lua]

http://docs.coronalabs.com/api/library/physics/newJoint.html

This will also handle the rotation… the weapon essentially becomes a part of the player’s body, within reasonable force limits (meaning that, weld joints can occasionally “flex” under extreme applications of force, but typically they are rigid).

Brent

If i decide to go for the classic way (animate my character with each weapon and use one sprite instead of 2 sprites), will it take a lot of memory comparing to the methods you guys described???

I don’t know the complexity of your animations, but it will take up a bit more memory, both texture and general.