How can we get two animations run simultaneously? - iphone

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.

Related

Missing correct collision behaviour of objects, when using moveTo action

i just started working with SpriteKit and encountered a problem:
I want to have an object, i call it playerController, that follows the players touch and a puck, with can be hit by the controller and will in that case bounce of the controller.
Somehow like an AirHockey game.
I constructed 2 SKNodes, with texture and physics, so they bounce of each other properly if gravity is on or if the controller is moving by some velocity.
BUT if the controller is moved by the following action the puck does not bounce of.
SKAction *moveTo = [SKAction moveTo: CGPointMake(touch.position.x ,touch.position.y) duration: 0.1];
[self.controllerPlayerOne runAction: moveTo];
Why? I already searched in the documentation and in several tutorials, but none addressed my problem. Maybe this is wanted by the SpriteKit developer, but how is in this case the realisation of following an touch?
Hopefully someone can help.
Edit:
Currently, i got the controller puck behaviour by setting the controllers position to the touch position and calculating the speed by using the last and the current position of the touch, each time the touch moved.
This is working pretty good.
This is by design. The same behavior can be observed in cocos2d btw.
The thing is: move actions move the sprite, not the physics body. Even if the physics body does follow the sprite, the move action overrules the physics body motion, at best putting it where the sprite is.
Instead when using physics bodies you must move them by changing the body's velocity, you can no longer reliably use the move actions. The physics body then moves the sprite.

Issue with zooming/scaling CClayer (cocos2d + box2d)

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.

How do I detect which direction a UIImageview is animating?

What is the best way to detect the direction of a uiimageview?
I want to detect when a uiimageview is 'falling' - this is because it follows an arc animation for jumping purposes, i only want to detect when it is 'falling' and intersecting a floor, rather than when it jumps and intersects the floor.
I'm guessing there is no built in method to do this.
Thanks in advance!
The best thing to do, I found, was to draw a path and test it for collision with any above 'floors' or platforms. Then if it does collide, draw another path with an end point matching the y position of the collided platform.

Creating a Body - Cocos2d/Box2d

I have a ball and another sprite. When the ball collides with the sprite it simulates falling.
My only problem is the other sprite is just on big image and the ball is on top of it, but there are spaces on the sprite and a lot of corners. I need to determine if the sprite has touch one of the corners. I know this is hard to understand.
So, my question is, is it possible to make a body without
b2PolygonShape blockShape;
and
blockShapeDef.shape = &blockShape;
OR
is there an alternative I can use? I cannot set the image as a box and it would take way to long to set edges because there are so many corners.
I have already set up the collision detection.
I really need help with this.
Thanks!
If you want it to react properly, you have to make a polygon using every single corner coordinate.
But don't be lazy about it. You can use SpriteHelper for creating *b2PolygonShape*s out of your sprites.
Or another alternative: VertexHelper

Cocos2d - Creating collidable Sprites?

Hello everyone I an very new to cocos2d, so I apologize if this is a simple question. I would like to create to sprites that collide when they hit each other.
For instance, one sprite, spriteA, is in a fixed position on the screen. And another sprite, spriteB, is moving around the screen. SpriteB will collide with spriteA. If that doesn't make sense or you don't understand it, tell me and I will elaborate further. Any help is appreciated. Thank YOU!
Try using Chipmunk or Box2d physics systems. These are included with Cocos2d and work by having a physics simulation that updates with every time the graphics change on screen.
The physics simulation will tell you if two objects are overlapping, and will provide physical attributes like weight, slipperiness (friction), speed and direction, which creates reactions like bouncing, sliding, realistic loss of speed and changes of direction on impact.
If you are new to physics simulation, here's a 30 second run down:
Create "bodies" in the physics simulation that represent each graphical sprite
Bodies are usually defined more simply than their graphical counterparts, like a circle, square or simple polygon shape
In order to update the graphics on the screen accurately, first you establish a pixels to meters ratio. Meters are notional (i.e. made up) measurement that is used in the physics sim
Each time the physics simulation "ticks", you update the graphics on screen accordingly
So if a body in the physics sim moves 1 meter, you might transform the pixel sprite 32 pixels
Here's a good tute on collision detection using Box2d.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
enjoy
Its actually very simple:
Just schedule a timer: [self schedule:#selector(checkForCollision:)];
Specify the method: - (void)checkForCollision:(ccTime)dt {}
In the curly braces, make CGRects for each sprite using CGRectMake.
Then in the same method, just call: if (CGRectIntersectsRect) {}
That easy!
Well technically speaking when the 2 sprites interact, or share at least one common point, then they are colliding. I'm a little confused by your question. Are you asking for direction on how to make the sprite move on screen, or are you asking how to handle the actual collision(such as calling a method if they collide)?