How to get hold of a sprite in cocos2d? - cocos2d-iphone

in cocos2d I need to drag a sprite in my project using finger. how do i get hold of that sprite? any help will be appreciated. thanx. i am using chipmunk engine.

You need to capture the touch began, work out what sprite is being touched and then track the movement of the touch. In touches moved you update the position of the sprite.
Sound complicated? It's not really. Here is a great tutorial for it.
http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d

Related

Particles around a sprite

I'm new to the CoCos2D development. I have checked out some tutorials and went on trying to develop a little idea.
I have checked some partical tutorials and it all looks nice but I still have some questions about it. I have seen how to call a particle and let it follow wherever you click on the layer and so on but I need something more.
Let's say I have several circle shaped sprites on my Layer. Is it possible to do the following: click on a sprite and then a partical trail should go around the sprite so you as a player can see it is selected. The particale should keep circling around the sprite until I select another circle shaped sprite which result in dissappearing of the previous particle trail and appearing onto the new selected sprite.
Is this possible with the particle system or should I look for another way of doing this ? Any type of help is appreciated.
kind regards

Scrolling Background with Cocos2D and Box2D

I am trying to create a simple game that mainly consists of a ball rolling down an incline. The player's only control is to cause the ball to jump. My question is, what is the best way to make it appear to roll while generally keeping the ball at the same place on the screen? I have considered CCCamera, but it seems like it's not the best option since I want a repeating background image. Scrolling the background manually is also giving me trouble because it's not clear how to get the ball to stay in one place while letting Box2D handle the physics. I'd appreciate any help as I've been stuck on this for quite a while.
Use CCFollow on the layer where you draw the game stuff, and let it follow the ball sprite:
[gameLayer runAction:[CCFollow actionWithTarget:ball]];

Sprite does not jump when moving

I'm making a platform game, and everything was great. My sprite moved when i touched the left side of the screen, and jumped when i touched the right side. But then i decided to make it move by itself. so i added the ccmoveto function, but now it does not jump! I'm new to cocos2d but everything is working ok, except this, already searched but couldn't find the answer can someone please help me?
I tried everything, but it only jumps if i delete the ccmoveto action.
I'm using cocos2d 2.0
Thank you!!
CcMoveTo will override any manual position changes, inluding changes from other actions like CCJump. Your character is set to move to destination in a straight line, no matter what.
It's issues like these why I always recommend not to use actions for gameplay logic. Especially position, you need to retain full control over it. Use a direction vector and integrate position every update: and you're free to do everything you need.
my advice is to use one of the physics engines provided with cocos2d: Box2D and Chipmunk physics. Thanks to this engines you can define the characteristics of the world (i.e. gravity vector) a shape and a mass for your sprite (i.e. a rectangle with a weight). Then when you need it to jump you will just create a force vector with the characteristics you need (i.e. angle, etc.) and keep updated your sprite with its physical body. This will make your sprite jump and land quite realistically.

Cocos2d change image of hero in accelerometer when an object hits it

Hi. I am new on this website and also in cocos2d. I am a student and I need your help.
I am making a game based on one of the tutorials in a cocos2d game development book. The concept is simple; different objects are falling from the top of the screen and I have to avoid or catch them by tilting the device. The main character, which is one which has to avoid objects, has different properties which can change by grabbing different objects (e.g. the player may have a shield if it grabs one). In order to display the shield I have to change the sprite of the player. I am not sure how I can achieve this. Could anyone help me in providing some guidelines on this?
Use setTexture to switch the image (texture) of your current sprite with another:
[playerSprite setTexture:[[CCTextureCache sharedTextureCache] addImage:#"playerWithShield.png"]];

cocos2d how CCSprite to appear on screen

I want to animate the way a CCSprite appear on screen.
At the moment I'm using "addChild" to display the sprite on screen but I want it to appear on screen with animation.
Is is possible?
Thanks
Try reading through the Cocos2D programming guide, there is a subject on animation with source code there. http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index.