tags:

views:

1072

answers:

2

How do we capture left move and right move and top move event using cocos2d?

I am taking one sprite(car) and if I move left it should move to the left on screen and to the right if you move to the right.

A: 

There are a few ways to implement movement in an iPhone app.

  1. You can use the accelerometer (tilt the device around various axis.
  2. Tap and drag. You can monitor the direction of a drag and move your sprite accordingly.
  3. You can use a simple tap mechanism where tapping on the left side of the screen moves the unit left, and tapping on the right moves the unit right.

Hope this gives you some ideas.

EightyEight
+1  A: 

Cocos2d uses custom callbacks called ccTouchesBegan, ccTouchesEnded, etc... basically the same callbacks you'd use in a regular UIView to detect touches, or accelerometer changes, but with Cocos2d the letters 'cc' are appended - this allows for event propagation to occur.

You must return kEventHandled or kEventIgnored - these events are only passed onto Cocos2d Layers. If multiple Layers are in the scene, each layer will receive the event (in the opposite order they were added to the scene, not their z-order). If you return kEventHandled, the event is then dropped and not passed further down the chain, otherwise the event is passed further down the chain to the next Layer until kEventHandled is returned, or all layers have been given a chance to handle the event.

David Higgins