views:

133

answers:

1

HI, I want to develop and app where a ball will be moved according to the direction of shake.The ball also bounce when it reach on edge....just like real world tennis ball....please give me initial idea....i want to go with cocos2d....can it help me.....

Thanks

+1  A: 

Your drawing code won't make much of a difference, I will assume you know how to draw what it is you want to draw. What is important here is setting up physics. If you have a physics engine running (like Chipmunk or others) then the effects of the shake to move the ball, which I'll get to in a second, may cause the ball to move in a different direction, if that's how you've written your physics. Keep this in mind. I'll assume for the moment that gravity is off.

The idea you want to do is first to figure out whether or not you're going to target iOS prior to version 3.2, because our gesture APIs are different between the two (one way works in 3.2 and later as well, but you really want to use gesture recognizers if you're not worried about supporting 3.0 or 3.1).

If you do want to support prior iOS versions than 3.2, then you'll want to look at the apis for motionEnded:withEvent: and motionBegan:withEvent: this will give you information about the motion of the device. Your final decision about whether or not it was a shake, and the details about the shake, should be done in motionEnded:withEvent: so you don't misfire. In here, you want to move the ball according to the information you get about the shake.

As for gesture recognizers, the same really holds true, though the APIs are so much easier. You simply create a shake gesture recognizer, and tell it what you want to do when it finds a shake. Real simple, but only available on iOS 3.2 and higher.

jer
Hi,i know about gesture recognizer(prior IOS3.2)....and also shake detect or others...also i know to draw what i want to draw...main problem is the physics....i am worried about how i move it smoothly or...how to bounce.....don't about physic engine....i think u r expert in physic engine.....can give sample code or refer me to some link....maximum link i found is not properly describe....
Rony
I can't give you sample code off the top of my head, but what you want if you know what physics engine you're going to use (be it Chipmunk, Box2D, whatever); you need to set up your shape which represents the ball, give it some mass, velocity, etc. Then you need get the ball moving along either a path, or with the help of gravity. There are many guides out there for the two physics engines I have listed, I can only go into so many details here though.
jer