How does one run an animation or a series of pngs(e.g. 4 pngs) on a CCSprite?
Constantly make the CCSprites image be this animation series?
Also, how does one rotate a CCSprite's orientation? e.g. 45 degrees rotation to the left or right
Thanks
Yes, you want to update the sprite's source every so often according to a timer.
For rotating, check out this tutorial: http://www.raywenderlich.com/692/rotating-turrets
Related
On tapping on screen I`m gonna apply impulse and angular rotation to sprite to move it to the sides. But after some time OR parameters of physics body attached to sprite should go back to initial (impulse 0, angular speed = 0). What are the best ways to do that (use CCAction or on update detect parameters of physics body and change them to initial)?
If i were in your position, I would probably start a timer at the first collision of the sprite and then use a CCAction to transition to the initial state to make it look smooth. Don't know if its the best way though.
When rehearsing Cocos2d V3 physics with debug mode enabled I noticed that physics body attached to its sprite has different anchor point from that of the sprite itself. Here's how it looks:
And this is how I create a sprite with physics body:
CCSprite *beam=[CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:#"w272.png"]];
beam.physicsBody=[CCPhysicsBody bodyWithRect:beam.boundingBox cornerRadius:0];
beam.position=ccp(125, 160);
[physicsWorld addChild:beam];
Do you have any idea how to fix this? I don't set any anchor point anywhere.
Physics objects automatically calculate a center of gravity, which is slightly different than an anchor point. Your real problem though is that you are using the sprite's bounding box as the rectangle to create the body and that's expressed in local coordinates. You want to make a text that goes from (0,0) to content size.
I have a problem and I saw it also in the game Candy Crush Saga, where they successfully dealt with it. I would like the sprite to show only when it is in the board (see image link below). The board can be of different shapes, like the levels in the mentioned game.
Has anyone some ideas how can this be achieved with Cocos2d?
I will be very glad if someone has some tips.
Thank you in advance.
image link: http://www.android-games.fr/public/Candy-Crush-Saga/candy-crush-saga-bonus.jpg
In Cocos2d you can render sprites at different z levels. Images at a lower z-level will be drawn first by the graphic card and the images (sprites) with a higher z-value will be drawn later. Hence if an image (say A) is at the same position of the other but has a higher z-value you will see only the pixels of image A where the two images intersect.
Cocos2d uses also layers so you can decide to add Sprites to a layer and set the layer to a specific z value. I expect that they used a layer for the board (say at z=1) with a PNG image containing transparent bits in the area where you can see the sprites, and a second layer at z=0 for the sprites. In this way you can only see the sprites when they are in the transparent area.
Does this help?
I found out Cocos2d has a class CCClippingNode which does exatclly what I wanted. First I thought it can clip only rectangular areas, but after some research I found it can clip also paths.
I am working on cocos2d-iPhone. I want to rotate stars with respect to its y Axis like it is in CUT THE ROPE game. I know we can rotate star to its x axis simply by ccRotateto action. Here is the link of CUT THE ROPE GAME.
http://www.youtube.com/watch?v=qoYJMaGPas4
In this link all the stars are rotating at its Y axis. You can see that in first star as it is steady.
Anyone has any idea how can we implement this??
Cocos2D has the CCOrbitCamera action that might work for you:
[[CCDirector sharedDirector] setProjection:kCCDirectorProjection3D];
CCOrbitCamera *orbit = [CCOrbitCamera actionWithDuration:1.0f radius:1 deltaRadius:0 angleZ:0 deltaAngleZ:360 angleX:0 deltaAngleX:0];
[mySprite runAction: orbit];
You can modify the angles to get the effect you're looking for.
that is done by animation frames. you need to have the rotation animation frames and you can run animation with frames to get that effect.
Using Cocos2d and Box2d I have made a rope of revolute joint segments with a body attached to the lowest segment (weldJoint) which I move using a mouse joint. The rope is hanging downward. How can I set conditions to tell when the attached body has covered double the distance it is swiped (mouseJoint) in the opposite direction. For example, if I swipe the body (attached to the rope) 45 degrees to the left I should know (maybe by some message or something) when it swings back 45 degrees to the right. Please help.
Perhaps I'm oversimplifying, but have you tried adding a sensor (Section 6.3 of Box2dManual) when you release it? If your physics are pretty simple, you should be able to get away with adding it at the same Y as the release point and making it's X flipped about the joint location.