Cocos2D camera movement? - iphone

What is the best way I center the screen to follow the character? Should I use CCCamera or just move the background around?
I am new to cocos2d so please show me exact code.
BTW: I am also using box2d in this project.
Thanks

Try this...
[self runAction:[CCFollow actionWithTarget:(your hero) worldBoundary:CGRectMake(0,0,1050,350)]];
It will follow your character (your hero).

Hey there,
You have always to choose between the best way and the best way in your situation. A problem has multiple ways how you can solve it. So I can just tell you how I did it.
A few weeks ago I released my first game. (If you are interested check it out: Birdy!) I also used Cocos2d and had the same problem like you. The player should always be in the center of the screen. I've choosen the way to move the background. I added 2 things to the GameScene: The background and the bird. And I set the background as the bird's delegate. So as soon as the bird performs a jump for example, the background is moved in the opposite direction.
I think for my situation it was the best method. But I can't talk about CCCamera because I never did anything with that class...
I hope I could help you a little bit. But it's always a bit difficult to find the right way. So you should also think about things you will optionally add in the future. So perhaps my way does not fit your requirements...
I hope also my english is understandable...
Sandro Meier

Related

Swift Outlined SKLabelNodes

I am making a game with SpriteKit's framework. How would I make an outlined text with SKLabelNodes? There doesn't seem to be a built in function of doing this. If there is no way to do it within SpriteKit, what other ways could I approach this?
Ok, so I didn't know how to implement UILabels or NSAttributedLabelNodes onto a SpriteKit GameScene, so I just put 4 SKLabels in black behind the original SKLabel (same font size). I then adjusted the 4 black SKLabels, one going a little to the left (relative to the original label), a little to the right, a little up, a little down. This gave an outlining illusion. Pretty bootleg solution but it works. Hopefully SpriteKit implements a better built in option!
Hope this helps someone!

Create slider similar to the unlock slider of the iphone

i read some questions here about UIGestureRecognizer but i am not sure how to accomplish the following task:
I would like to create something like the unlock slider of the iphone, but sliding a button around a circle. In this case i donĀ“t need to look into the UIGestureRecognizer class, do i? I need an animation class or something...If you gave me some key-words to start with i would be really happy :)
maxi
You might try this page as a starting point
http://denizdemir.com/2011/03/07/animated-slider-iphones-cool-first-impression/
To do the circle version will involve a fair bit more work I'd say as not only do you need to read the circle gesture you also need your lock to move around the circle...
http://iphonedevelopment.blogspot.com/2009/04/detecting-circle-gesture.html
http://forum.unity3d.com/threads/13494-Messing-around-with-gestures
Could be there is a far simpler way to do this now but I'm not aware of it. Good Luck!
Here's another one:
slide to unlock" clone from the iPhone's lockscreen using only public
APIs
https://github.com/iosdeveloper/SlideToCancel

how to add a repeating background in cocos2d

I am new in iphone and as well in cocos2d
I have some queries about a game i am working on it.
Actually i have a background with some trees and bushes.and i have an object which keeps on moving and my background of trees and bushes is static at the back. I want the application to repeat the background and it give me a look that my object is moving forward.
Can anybody Guide me please.
I also want to implement speed so also guide me that how can i change the speed of background repetition. so that it gives a look that my object is slow or fast
Thanks
waiting for your positive response.
Regards
sHaH
Work through this excellent tutorial:
http://www.raywenderlich.com/3857/how-to-create-dynamic-textures-with-ccrendertexture
It'll surely help you.
The section "Repeating Backgrounds" explains how to make a texture repeat and animate it.
In order to change the speed you can make PIXELS_PER_SECOND a dynamic variable.

Cocos2D iPhone - Handling Touches Correctly

I am not a newbie to Cocos2D but I am building quite an advanced HUD with several sliding and overlapping CCLayer and CCMenu/CCMenuItemImage objects.
They are all responding to touches correctly in turn. However when things overlap, it seems the buttons underneath take priority over the things on the top, no matter what order I add them to the world.
Indeed, even implementing the registerWithTouchDispatcher method and returning YES/NO ccTouchBegan:withEvent: seems not to have the correct effect. It also appears that ccTouchBegan:withEvent: is then called on all buttons/menus in the world rather than just those underneath the touch.
I'd really like advice on a reliable way to detect and consume a touch on an object that is top most in the view without anything else hearing about the touch.
Thanks in advance!
How about this commit for develop branch of cocos2d-iphone?
v1.0.0-rc3 or earlier doesn't have the mechanism for touch priority. This commit seems to implement it.
Why can't you use tags? I'm not sure at the moment how to check z order but I would personally probably just use tags.

iPhone: An UI question

I want to implement an UI which should look like Speedometer. Is there a way to implement like that? Some of apps i seen that they have implemented. For ex. an app called "TaxCaster" implemented it. Could someone help me how can i achieve it?
Thank you in Advance.
That is possible yes, but it will not be easy. You will have to either use OpenGL or Core Animation. I would suggest the latter if you want something like they have in TaxCaster.
You can find more about Core Animation here.
I hope it helps.
A possibility is to simply have two UIImageViews:
A background that has all the measurement listings (i.e. the ruler part), and another that would act as your needle, pointing to the current measurement. All you would need to do when changing the current measurement would be to use the transform property to rotate it into the correct position.
Not a trivial amount of work, but it shouldn't be too hard.