I want to show an effect of falling blocks which settle down at pre-determined position after some falling animation.
Can this be done without using physics engine?
I found a better and easier way to do this in cocos2d by using CCJumpTo action
CCActionInterval *jump1 = [CCJumpTo actionWithDuration:3 position:sp.position height:150 jumps:2];
sp.position = ccp(10,100);
[sp runAction:jump1];
Where sp is the CCSprite for the block.
All you need is to simulate gravity, the acceleration of the object. This could be achieved quite easily with a custom animation curve. Please have a look at this QA "how-to-create-custom-easing-function-with-core-animation", which shows a way to create the curve you need. Here is some more about "Animation Types Timing" by Apple.
The function you are looking for is called
functionWithControlPoints, which has four input parameteres, so yes you can put in any random element you wish with a custom curve.
"Easing" is your answer. You can choose the method that you need visually from the links below.
Tim Groleau's easing generator
jQuery Easing Demos
Related
I was wondering if there is a tool that will allow me to construct/trace a closed bezier curve based on a background image?
Basically I have a background image that represents some 2d curve which could be of some weird shape like a race track and I want to place some items along this path.
I figured that if I can derive a quadratic bezier curve that will overlap the image I would be able to use the mathematical equations for this curve to compute individual points along its path..
Does anyone know if such tool exists? Is my approach reasonable or totally off and there is a much simpler solution?
Thank you in advance.
I suggest building it yourself. It shouldn't be too difficult to build a level creator where you add your own background image, place your bezier key points along where they need to be and export the points into a plist. It'll even give you room for extending it and customizing it for your game.
Also, if you're planning on tracing a path along a road for a racing game, consider constructing the background from smaller road/tree/grass sprites. This way you can give them specific properties (such as canDriveOn, canHit and so on) and based on customized behaviour defined for each one of them, your 'driveable' path would be derived implicitly.
Skewing x and y coordinates doesn't give that kind of effect. Any ideas on how to achieve this kind of effect? I already use cccamera but there are no examples on how to properly implement this. This image btw is from cocos2dx tried the c++ code still didn't work
I feel I need to share this once and for all. So this is how camera works when you want a slanting ,45degree or pseudo3d view of your background :
First set your director to 3d perspective
[director_ setProjection:kCCDirectorProjection3D];
If you only want some of the sprites to appear this way then remember this
all nodes have camera (cocos2d v.3 doesn't seem to have it anymore I don't know why)
so you do this:
[mysprite.camera setEyeX:0 eyeY:-40 eyeZ:10];
[mysprite.camera setUpX:0 upY:0 upZ:1];
Play with the values that fits your need. Hope it will help others!
I'm new to using Box2d and really can't find a consistent answer to my question so please excuse me.
I'm writing a game for the iPhone -- who isn't these days -- and I'm using Cocos2d and Box2D. I have objects that move around in the game and I would like to give them a more of a curved path. From my studies I know that I should use body of type b2_kinematicBody which allows me to change the linear velocity every tick and keeps them from colliding with my other flying bodies. I do understand that if I know my current position (x,y) and my next position in the step (x1,y1) I would be able to compute the vector for velocity. Does anybody have a good way to give an object a defined curved path? I'm thinking it has to be some kind of parametric equation.
Take a look at bezier curves. After curve defenition you can compute the derivative (it's easy for bezier) and use it as a velocity for your body
OH whats the game called? sounds like a good one. have you looked into maybe just doing that in version 2.0
Have been working on building a Bridge builder using box2d.
Basically you build a bridge and stress test it by passing objects on top of it. The joints break if the stress applied is high.
Can you please help how best to join the b2Body. Have tried revolute joint, but they are not breaking. Any suggestions.
Thanks
"You can get the reaction force and torque off the joint. You can query these forces after each time step and destroy the joint when your threshold is exceeded." - Quote from Erin Catto - http://www.box2d.org/forum/viewtopic.php?f=3&t=1079
I think the joints will not break by themselves. You have to break them using DestroyJoint function. You can setup b2ContactListener and get the impulse velocity of the object that hits your bridge and you can take the decision if you want to break the joint or not.
I'm just starting with cocos2d + box2d.
I would love to create a simple 2d ship game where you look from top(from the sky) down at the sea with the ships.
Could someone give me a very very basic example, how to apply wind to my world? Do I have to applyForce to each ship body?
And what about the gravity? Since it goes straight down, should I set it to 0? gravity.Set(0.0f, 0.0f)? It actually would pull down the ship..
Should I somehow deal with the water? e.g with density of it?
you would probably have to detect where the ships are and then apply force on them somehow.
and yes set gravity to 0.
and water wouldn't have to be an object at all. just like a background image.
If you are looking from the top and want to apply wind force to all your ships you can use gravity vector. In this case wind force will be applied to your objects automatically.
If there are other dynamic objects on the scene then it's a good idea to keep the list (std::list or NSMutableArray) of pointers to all your ships. Notice, that by default box2D is clearing all the forces each simulation step. You can disable this property or apply forces manually each simulation step