iPhone - What is the best way to create the physics for a game? - iphone

1- let's say there is a box on the screen and as soon as it gets hit by another box it suppose to move. How can i detect (getting hit) on my box object? Is it a good idea to use an nstimer which runs every 0.1 seconds and looking for the location of other objects around itself?
2- What is the best way to display simple 2d animations?

Install the Cocos2d templates and then instead of using the standard Cocos2d template use either the Chipmunk or Box2d template. Box2d has the benefit of C++ where Chipmunk is C based. Both still use Objective-C though for a lot of stuff. Heres where Cocos2d is. Note: All three templates have animation abilities.

Related

Simple Cocos2d Iphone Game. Just some basic questions

I'm making an app, where the sprite has to run across the screen pressing buttons and jumping and ducking. Kind of like line runner. Anyways, I'm using cocos2d. Is this what i should be using. If it is, how would i make it. Im not asking for all the code, just the basic objectives and what i should do! thanks so much!
Cocos2d is one of the best platform to make game i think what you want to do can be done by cocos2d and you need to know how to move object(sprite) across the scene and how to detect the collation.
there is lots of way to move the sprite across the screen you can also move then by the cocos2d built in methods.
search for move method which will help you.
I would definitely advise you to use Cocos2d for this purpose and also Box2d if you need real physics simulation in your game.
Regarding of writing your game have a look here : It contains very useful cocos2d tutorials and even have a tutorial of how to write a full functioning game (Look for the monkey game)
Note : It seems that the link does not work right now but I am sure it will be fixed soon..

Iphone game cocos2d and box2d

I have image named "platform.png" that represents one brick for platform of a IPhone game. I have a cartoon character that will jump on this platform.
A series of platform.png will form one complete platform. These series will be generated by swiping finger across Iphone screen. When character will jump on this platform it should go down like elastic and bounce back up. Can anyone tell me how to do this ?
Thanks in advance.
What yo want is Collision Detection. I don't think using Cocos2d will be a great idea to use in this case because you want to show elastic and bounce effects which should seem real. For this, what I suggest, is using Box2d which clearly help in showing the effects in a natural way. Here Collision Detection can be handled in a separate class known as ContactListener. You can study Box2d and ContactListener here. In ContactListener you can generate these effects and this class is very easy to handle. Two or three months back I used the same to create my game Pogo Jump and believe me I was very easy to work on Box2d.
Good luck..!!
heye ,
you have two options for this , either use box-2d/chipmunk or dont.
If you have prior experience with Physics then i would say box-2d/chipmunk would look more realistic.

cocos2d game sample based on gameloop?

I want to develop 2d game through Cocos2d.but i could not find
any tutorial based on the following.I want one game loop and one draw screen.can I do Multiple sprite animations within one scene..(translating World etc).where can i find tutorial how to use those classes which are coccos2d?
-(void)gameloop
{
calculation();
drawImage();
drawImage1();
}
It is quite simple, you do not have to know opengl essentials to use cocos2d. cocos2d is quite simple yet awesome!. Just download the cocos2d 0.99.5 and it comes with sample tests. You will be able to find almost all of the things you want to do in a game i.e. animations, touches, moving sprites, particle system etc etc
so just go to:
http://www.cocos2d-iphone.org/
How to learn OpenGL by example, say, building a rotating globe?

chipmunk stack fall effect

I am using chipmunk cocos 2d iphone ,in which i have to show stack fall effect when the objects are placed on the edge of other
object.My idea is to develop the effect like "Tower Box " game. I would like to know which properties of shape or body will create effect like "Tower Box " game .please let me know how can I fall that stack.
Cocos2d provides you with a few preset project options.
One of these is Cocos2d with Box2d, another is Cocos2d with Chipmunk. It is completely up to you which physics engine you use, I have experience with both and personally, would recommend Box2d.
If you create one of these projects, it generates some example code for you, and in the case of Box2d (i haven't used an auto generated chipmunk project), you get a nice little app that spawns loads of boxes and shows them falling with gravity. You should take a look at the code behind creating the physics bodies on the boxes and adapt it to suit your application (spawn a box at a touch location, perhaps?). You could then add some logic that checks, on collision, the alignment of the falling box with the top of the stack, and either let it continue falling, or use a fixture to attach it to the box below.
For more information about using physics in a cocos2d app, as well as general cocos2d usage, check out this blog, it's what taught me in the beginning: http://www.raywenderlich.com/ [edit: just noticed there are no chipmunk tutorials on there, but the theory should be applicable to both. I found Box2d easier to use than Chipmunk]
What physics effects have you got on the stack so far? What problem have you encountered that made you question the physics properties of the objects?
For these effects you need a physics library. For 2d games box2d is quite good.

Iphone GUI physics code

When you drag an iphone GUI element like a list, it scrolls in a physics correct way, and also has a nice bounce effect at the end.
I would like to write a GUI element in my game, without using UIKit. I wonder where is the code implementing this, and if I can use it instead of trying to write something similar.
Any ideas?
I think that a physics engine would be overkill for just animating a gui element (unless you already have a physics engine in your game).
You could try using animations but I've no experience of doing this without UIKit but I suppose you would start here?
If you didn't want to use Core Animation, I would take a look at Robert Penner's easing equations - they're in actionscript but are pretty simple to port to C and would be a good start to get your own animation code started.
Hope this helps,
Sam
You can perhaps use animations to achieve this, you can define animation paths for bouncing or doing whatever it is you need and activate them when needed. I think the example project MoveMe can help you out
I can recommend the O'Reilly book "Physics for Game Developers" by David Bourg, which has great coverage of algorithms and code for all sorts of simulations. You probably want to start with motion affected by drag for the flick and gradual slowing, then look at a spring model to simulate the damping at the end.
box2d is an open source project that provides a great 2d physics engine.
this library is used by Intel clutter, which is a nice physics oriented UI library that is capable of running on mobile devices. that means that box2d is already optimized for mobile platforms like the iphone.