I am making a game in Cocos2d. It has a 'shoot' button. How can I make it so that it:
1. Recognizes that the button sprite was touched
2. Perform a method that will actually load the bullet graphic onto the layer and
3. Have it moved at a steady pace across the screen (like a real bullet)
Any help is appreciated. Thanks!
Great questions, all three, and all are covered in the various Cocos2d getting started books (Yes, books!) and guides! To answer your questions specifically would require that you answer a number of questions about how you've set up Cocos2d in the first place; what kind of map you are using, whether and which physics engine, etc....
If you haven't answered those questions yet, best to start by researching Cocos2d.
Start here.
I haven't read the book(s) available, but Ray Wenderlich's Cocos2d tutorials were incredible helpful and demonstrative.
If you're subclassing CCLayer, set the isTouchEnabled property to YES. You then receive callbacks like -ccTouchesBegan:withEvent:, -ccTouchesMoved:withEvent:, etc. Your button handling code would go in those methods. See the documentation on CCLayer and related classes for more information.
Set the isTouchesEnabled to TRUE in init. And just get rectangular co-ordinates around your button sprite and then in touchesBegan just check whether the touched location is inside the rectangular button area, if it is inside it just call your respective function.
Related
I'm making an app, where the sprite has to run across the screen pressing buttons and jumping and ducking. Kind of like line runner. Anyways, I'm using cocos2d. Is this what i should be using. If it is, how would i make it. Im not asking for all the code, just the basic objectives and what i should do! thanks so much!
Cocos2d is one of the best platform to make game i think what you want to do can be done by cocos2d and you need to know how to move object(sprite) across the scene and how to detect the collation.
there is lots of way to move the sprite across the screen you can also move then by the cocos2d built in methods.
search for move method which will help you.
I would definitely advise you to use Cocos2d for this purpose and also Box2d if you need real physics simulation in your game.
Regarding of writing your game have a look here : It contains very useful cocos2d tutorials and even have a tutorial of how to write a full functioning game (Look for the monkey game)
Note : It seems that the link does not work right now but I am sure it will be fixed soon..
I am new to iPhone development, and I am looking for someone with experience
to simply tell me whether I am on the right path or to perhaps point me to it
regarding what I am trying to acheive.
I am trying to develop a character animation that reacts to the volume of
the microphone input. Something like Talking Tomcat, except that instead of
having just a face react to the volume, an entire character´s body is involved.
The character has been created in illustrator and it is image based. So
this will be a 2D animation. I have created numerous frames for the different
kinds of reactions the character will have depending on the volume.
For my animation I am using UIViews using its Animation resources and adding
UIImageViews as subviews. I am also using CGAffineTransforms for rotating
images.
I am also relying on Timers to control the different stages of the
animation.
To allow for a more flexible animation, I have created UIViews for the head,
arms, torso and legs of the character. These have been severed into their own
images and I am manipulating these images individually through UIViews.
I can go over my code in more detail if necessary, although any help will be greatly appreciated even if it is something off the bat.
Seeing that you're not an advanced ios developer I would suggest starting with cocos2d.
It has everything you need to start with animation.
Web page and forums has plenty of information on how to do it and... what's most important [to me at least], you've got gurus like Ray Wenderlich writing excellent tutorials like:
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d
Which is the best approach to create a side Scrolling racing game?
Should I just move the background or work with the camera instead? I read in lots of places that moving the background is the way to go, but how do I handle the other players?
Sorry if this is a noob question but I'm a bit confused.
i think the best way is to set a point in your scene called ancher which doesn't move in your screen but and calculate every other position relative to it. the ancher is moving along side every other player but in a controled manner (for example you can set it in the middle of your track along side with player), in this case you only have to move the background according to your ancher and then you calculate the other positions all relative to the ancher. it may look a bit complicated but implementing this is much more easier and bugfrier than any other method.
Bind all your players to your background (make them children). Then no handling will be required at all
If you want lots of customization then make your own methods for moving the background, players, etc.
If you just want simple player following then use:
[self runAction:[CCFollow actionWithTarget:(the player's CCLayer) worldBoundary:the World's Boundaries in CGRect]];
or simpler:
[self runAction:[CCFollow actionWithTarget:(the players CCLayer)]];
I am going to work on a game project. I am using cocos2d. I want to use cccamera class of cocos2d. Please tell me about any tutorial on cccamera. I want to implement more or less like angry birds, throwing the ball that reaches its destination facing the obstacles in the way.
So when the ball moves ahead the scene accordingly moves back depending on speed of the ball.
How to manage all that. I think i should use cccamera.
Thanx.
CCCamera, per the documentation is used for 3D effects (http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_camera.html) and recommends the use of CCFollow (http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_follow.html) for 2D related effects (such as following the birds forward, etc).
I'm a beginner when it comes to iPhone development and i've searched for the answer to this question and haven't found anything yet.
What i'm trying to do is allow the user to move an object without actually touching the object (they can touch anywhere on the screen) and as they move the object will go from where it was originally and move in the direction of the users movement but not jump to thier touch location and be covered up by their finger.
Any help you can provide would be phenomenal
Thank you in Advance,
BWC
You can subclass a UIView to track the touch movements by overriding the touchBegan:withEvent:, touchMoved:withEvent: and touchEnded:withEvent messages. In these messages, track the UITouch objects' locations (converted to points on the view by using the convertPoint:toView: message of the UIView you're subclassing) and calculate the difference of movement; then apply the same difference to your object, wherever it might be on the screen.
I know this is old.... But here is a great tut doing this with Cocos2d and sprite animations.
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d
Derek