Search code examples
ioscocos2d-iphone

How would you get CCSprite current velocity as a value


I am trying to calculate when the sprite which is affect by gravity starts to fall down. I presume I can get the velocity value for when it turns into a negative?

Is it something like this if I was trying to get the current velocity of a sprite on the Y axis?

_sprite.physicsbody.velocity.y

So if I had it in the update method

int velocityY = //Whatever I need to do to get the velocity.

Solution

  • Put both together, and use to proper data type, and you're in business:

    CGFloat velocityY = _sprite.physicsBody.velocity.y;
    if (velocityY < 0.0)
    {
        // moving down ...
    }