With or without CCAction ?

Hi!
There are at least two ways of doing moving or another things with sprite objects:

  1. Use update function where you can update your coordinates
  2. Use Actions.

Now I’m thinking about what would be better. I don’t want to generate flame or something, I just need an advise.
So…
I’m not sure about some things but I’ll tell you how I understand it…
For example I need my object to accelerate. What should I do in both of ways ?

  1. In update func I just need some formula being applied to my object.
  2. If I want to do it by action, I should derive from CCAction and make my own action. Am I correct ? If so, it’s good, if not… mm… is it possible ? )

So both variants are good. But what should I do if I have a complex object ? For example bicycle. It has wheels, handle bar, pedals and so on. For example I want my bicycle to move. Again:

  1. In Bicycle::update(float dt) I put some code that make every sprite according to the rules I invented for my game.
  2. I’m not sure what to do here… Should I create an action for each sprite ? Isn’t it bad? - because every time you make an action you do new() - allocations.

I just a little bit confused about Actions philosophy.

Thank you in advance.:slight_smile:

If you have a collection of sprites that should stay together then you might consider grouping them under a CCNode and just mode the CCnode?
You could make a class for your bike and inherit from CCNode or CCObject.
You can then put any code you want in the class but still use it as a CCObject / CCNode.

I think these is a move to that uses acceleration, cant remember the name.

Edit. there is a 3rd way, if you use Box2D then you just need to set your sprite position based on where Box2d says it should be.
Let Box2D handle the maths.

You could use joint to make your bike objects stick together and have suspension etc.

There is a good Box2D demo:-
http://www.emanueleferonato.com/2009/04/06/two-ways-to-make-box2d-cars/

Scroll down to the Truck demo, it looks like a bike from the side.

Thank you, Adam! :slight_smile:
I’ll try to define my own CCAtion.

Good luck!