0

I'm trying to create a top down car game where the camera follows both the player and the player's rotation. I can get CCFollow to work easily, but I have had no success with CCCamera. I assume that I need the camera in order to make rotation follow the player (i.e. have the player facing up at all times) but I have had no luck on google.

Can anyone either provide a code snippet or a tutorial on how to create a rotation-following top down camera?

Cheers!

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Daniel G. Wilson
  • 14,955
  • 2
  • 32
  • 39

1 Answers1

1

My suggestion: don't use the CCCamera.

Your game design requires the car to move over a track. In programming terms this is often much easier accomplished by keeping the car static, and instead moving the background underneath.

Assume your car is at the center of the screen. It's supposed to move from left to right. Instead of moving the car or the camera, move the background layer - just in reverse: move the background layer from right to left to make it seem like the car is moving from left to right.

The same is true for rotation. If you want the car to turn left, rotate the background in clockwise direction.

This is a lot easier and can be accomplished simply by changing the position and direction properties of the background layer. Note that you do not need to do this for each object in the background layer, it's sufficient to add all objects to the background layer in the appropriate positions and then just change the background layer properties. The layer's children will follow accordingly.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • I understand the concept of moving the other stuff to create the illusion of the player moving, the problem is that the play should move from the middle of the screen when the camera or whatever I end up using reaches the edge of the world. – Daniel G. Wilson Oct 11 '11 at 19:35
  • I'm also confused as to how the player's car would interact with the enemies/opponents assuming that I did use different layers. I'm trying to use Box2d. – Daniel G. Wilson Oct 11 '11 at 19:36
  • The visual layers have nothing to do with the collisions. As for the world borders, why not extend the world visually so that the problem never occurs? – CodeSmile Oct 11 '11 at 21:23
  • I may end up doing just that. It actually didn't occur to me that I could ignore the orientation of the collisions and simply rotate the visuals. I still would prefer it if I knew how to approach those shortened world borders. – Daniel G. Wilson Oct 12 '11 at 01:27