Issue with zooming/scaling CClayer (cocos2d + box2d) - iphone

im making angry bird like game in cocos2d & box2d for Iphone, in which i need to zoom out my camera view as my thrown body goes out of screen and later on it should be zoom in as per normal position.(if u have played angry bird in mobiles i hope u got what im exactly stucked into) i'v tried to scale my whole layer but not worked as per need.can i use camera of cocos2d to achieve this?

You have to use scale factor.Camera will not zoom in and out, it will only move horizontally and vertically on your scene
Use scale factor in action to go give it animation effect as in angry birds
id myAction = [CCScaleTo actionWithDuration:0.5 scaleX:2.0 ScaleY:2.0];
[self runAction:myAction];
That should do it!

The best option is to use the scale factor of the CCLayer.
self.scale = someFactor;
someFactor ranges from 0 to 1.
In order to achieve a cool effect, you could try to change the factor proportionally of the velocity of your sprite. I recommend that you use a schedule to change the scale over time.

Related

Is it any good to make play game in zoom out condition?

I'm developing a game with large obstacle and sprites(in cocos2d+box2d for iPhone), then after zooming out my sprites and layer (by increasing cameraZ), I make my game to play by user, which causes some problem in touch detection of dynamic objects.
Can it be said a good approach to work with? If No then what will be the solution to work properly(consider that I have traveled so far with this approach)?
NOTE:[self.camera setEyeX:0 eyeY:0 eyeZ:180]; (i'm using this line for zooming out, putting camera far from my sprites by increasing z)
If you use a camera for zooming then cocos2d will no longer correctly convert your touch locations to opengl coordinates, since it doesn't invert the camera transform. I would recommend using scale on the layer that your objects reside on to implement zooming. This gives you precise control over the zoom factor and touches will be correctly transformed when you use methods to convert touches from screen space to node space.

Zooming In/Out of a OpenGL ES 2D Game Scene

What's the best method for pulling back to show more of a view in a 2D OpenGL iPhone game? For instance, in Tiny Wings, when the bird flies toward the top of the screen the bird and the scenery pull back to simulate the bird going higher in the sky. Would this effect be better achieved by scaling all the sprites proportionally, or by using glOrthof? In any case, I'm assuming that the zoom-out factor is inversely proportional to the player's y position.
You almost certainly want to use glOrthof so all you're changing is how the camera sees the scene. This avoids recomputing all the normals and such in the scene, saving quite a bit of work. It's also easier for you to implement.

Cocos2d Accelerometer Movement

I was wondering how you would move a CCSprite right and left by tilting the device right and left. Like in the falling balls app.
Try this:
http://www.cocos2d-iphone.org/wiki/doku.php/tips:using_accelerometer_for_sprite_movement
it is an example code to move the sprite on a plane surface along the x and y accelerometer axis as per the tilt.
The first solution provided is dependent on Chipmonk which is a 2d physics engine. The accelerometer can be used to move a CCSprite without the need of a physics engine. There are several ways to achieve what you want.
This is a great blog with awesome tutorials to get you moving in the right direction.
http://www.raywenderlich.com

How can we get two animations run simultaneously?

I am writing a game in iPad using cocos2d.
I need to mix two actions,
One action is, to get the rotation of the object. I have 10 images of the rotation of an object. When we animate them we get the rotation of the object.
Second action is to move the object from one edge to other edge. I am able to get one action after the other.
But I need both actions at same time.
The object should rotate while it moves from one edge to opposite edge. How can I mix both the animations.
Thank You.
I hope this may help
[sprite runAction:[CCSpawn actions:action1, action2, nil]]
or try this when u got only 2 actions
[sprite runAction:[CCSpawn actionOne:action1 two:action2]]
or you can do like this
[sprite runAction:action1];
[sprite runAction:action2];
I have 10 images of the rotation of an object. When we animate them we get the rotation of the object.
You're halfway there.
Modify the images so that they go from edge to edge. Model both the rotation and the movement with your images. You'll probably need more than 10, though.
That way, you only have one animation to perform.

iPhone: Camera following player in cocos2d

I'm making an iPhone game in cocos2d.
I was wondering how I would make the camera / the view follow a specific sprite?
would I use the CCCamera class?
Yes, CCCamera would work. However, it has some drawbacks that make it undesirable for some uses. Moving the layers respectively all other objects relative to that sprite may be a better solution. It depends on the game.
First, read up what the different approaches and their drawbacks are, you can get a lot out of this cocos2d forum thread:
http://www.cocos2d-iphone.org/forum/topic/5363
It would be helpful if you could describe what your game is about and why you need the camera attached to that sprite.
For example, if you're thinking of a running game like Canabalt, i would not use the camera to scroll over the world, but instead scroll everything relative to the player (towards him) with the player sticking at about the same x coordinate while running. Perfect examples of games where you would not move the camera at all are the iCopter games, they are basically simplified versions of Canabalt. Notice that the player sprite always stays at the exact same x coordinate, and the game world just scrolls
Scrolling the camera itself in my opinion makes the most sense if you have a large game world that the player can traverse in all directions, and the number of objects are simply too numerous and also moving about in various directions, so updating their positions individually each frame would be both overkill and prone to errors. And since the game world is so huge, you would want to use the camera's position to limit what is drawn on screen.
use CCFollow actions
Like these :-
[self runAction:[CCFollow actionWithTarget:(u r hero) worldBoundary:CGRectMake(0,0,1050,350)]];
it will helps