Search code examples
ioscocos2d-iphonespritechipmunk

Cocos2d: Stick two CCSprite?


I am trying to superimpose sprites by drag and drop and when to sprites collide I want to stick them so if one fall the other sprite stack on it will fall two. Any ideas please?

Best regards

For more precision I need help on the stick part. Thanks


Solution

  • I'd follow these steps.-

    • Extend CCSprite to add a property CCSprite *spriteToFollow
    • You should also add a CGPoint to store the offset between two sprites when they collide.
    • Once one CustomSprite collides with another one, set the proper spriteToFollow
    • On CustomSprite init method, call to scheduleUpdate
    • On update method, if spriteToFollow exists, update the current to spriteToFollow.position + offset

    Hope it helps.