If this question is a duplicate, plz correct me.
What I want to do is to have a character on the screen who may hold a gun.
So if the background move, the character should move with it.
And if the character move, the gun should move with him/her.
Does anyone know how to do this?
Sorry for being a newbie
Kind regards
You can use a
CCLayerfor what you would like to do.A
CCLayeris a sort of “container” for all the sprites you want to control as a group. E.g., you create twoCCSpritesand add them to a CCLayer; you can define the sprites position in coordinates that are relative to theCCLayerand when theCCLayermoves, the sprites go with it.You can also have multiple layers, for different groups of objects. E.g., if you have more characters, they could all go into the same layer.
A
CCLayeris derived fromCCNode, so you could do pretty much the same by adding your character, its weapon, and the background to the same node; but I would suggest to have a node for the two sprites (character and weapon), and a layer for the background sprite and the character+weapon node.A
CCLayer, in comparison to aCCNode, adds the possibility of handling the accelerometer (if your want your character follow it) and touches.