cocos2d: animation – updating the sprite every X pixels of movement

-(void) updateFrames:(CGPoint)direction
{		
	unsigned int length = sqrtf( powf(position_.y, 2) + powf(position_.x, 2) );
	unsigned int index = (length / 5) % 2; // 2 = the number of sprites for the character's walk sequence

	// increase frame index, since frame names start in "1" and not "0"
	index++;
	NSString *str = [NSString stringWithFormat:@"Anim-player-walk_%02d.png", index];
	CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:str];
	if (frame) [self setDisplayFrame:frame];
}

cocos2d textured poly

https://github.com/asinesio/cocos2d-PRKit

cocos2d box2d destructible wall contact example

-(void) beginContact:(b2Contact *)contact{
	[super beginContact:contact];

	b2Fixture* fixtureA = contact->GetFixtureA();
	b2Fixture* fixtureB = contact->GetFixtureB();
	NSAssert( fixtureA != fixtureB, @"Bullet: Box2d bug");

	b2Body *bodyA = fixtureA->GetBody();
	b2Body *bodyB = fixtureB->GetBody();

	NSAssert( bodyA != bodyB, @"Bullet: Box2d bug");

	// Box2d doesn't guarantees the order of the fixtures
	b2Body *otherBody = (bodyA == body_) ? bodyB : bodyA;
	b2Fixture *otherFixture = (bodyA == body_) ? fixtureB : fixtureA;

	// ignore sensonrs
	if( ! otherFixture->IsSensor() ) {
	BodyNode *bNode = (BodyNode*) otherBody->GetUserData();
	if ([bNode isKindOfClass:[Bullet class]]) {
			if([(Bullet*)bNode canKill]){
				hitCount_--;

				if (hitCount_ >= 0) {
					CCSpriteFrame *frame = nil;

					switch (hitCount_) {
						case 2:
							frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"structure-damaged.png"];
							break;
						case 1:
							frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"structure-destroyed.png"];
							break;
						case 0:
							[game_ removeB2Body:self.body];
							[[game_ arrayEnemyWall] removeObject:self];
							break;
					}
					if (frame) [self setDisplayFrame:frame];
				}
			}
		}
	}
}