objective-canimationcocos2d-iphoneccsprite

Cocos2D - Automatically set sprite movement with speed


I was wondering how I could immediately make my sprite CCSprite *van move automatically from the start with controllable speed like int *speed = 1, 2, 3+. I looked around but all I found were not fitting my needs. Is there a simple solution to this problem?


Solution

  • You have to use a CCSpeed action:

    CCSpeed* speed= [CCSpeed actionWithAction: yourMoveAction speed: 1.0f];
    // yourMoveAction is an action like CCMoveTo for example
    [sprite runAction: speed];
    

    Then you can change the speed while the sprite moves with setSpeed:

    [speed setSpeed: 2.0f];