2009-11-20 1 views
4

css에서 배경 위치와 같은 cocos2d의 이미지 위치를 변경하려면 어떻게해야합니까? 위치별로 보면 ccp (200,150)와 같은 배경의 위치를 ​​의미하지는 않습니다. 예를 들어 5 (200,200) 개의 이미지가 포함 된 (1000,200) 해상도의 이미지가 있습니다. 이 이미지를 (200,200) 스프라이트로 표시하고 이미지 위치를 변경하여 1 개의 그림에 5 개의 그림을 표시 할 수 있습니다. 내 생각에 달리기와 같은 움직임을 보이고 싶다면 10 프레임의 움직임으로 스프라이트를 사용하고 그림의 위치를 ​​바꿔 사람이 움직이는 것처럼 보일 것입니다. 어떻게해야합니까? 사전에 고맙습니다cocos2d 스프라이트 애니메이션

답변

9

나는 그것을 발견했습니다

AtlasSpriteManager *mgr = [AtlasSpriteManager spriteManagerWithFile:@"ax.png" capacity:6]; 
AtlasSprite *sprite = [AtlasSprite spriteWithRect:CGRectMake(0, 0, 200, 200) spriteManager:mgr]; 
[sprite setTransformAnchor:ccp(0,0)]; 
sprite.position = ccp(100,100); 
[mgr addChild:sprite z:0]; 

// Add manager to this layer 
[self addChild:mgr z:3]; 

// Create animation 
AtlasAnimation* animation = [AtlasAnimation animationWithName:@"testAnimation" delay:0.1]; 
assert(animation != nil); 

// Define the frames in the sprite sheet used for the animation 
[animation addFrameWithRect:CGRectMake(0, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(300, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(400, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(500, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(600, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(700, 12, 200, 200)]; 
id action = [Animate actionWithAnimation:animation]; 
assert(action != nil); 

// Run the animation 
id repeatAction = [Repeat actionWithAction:action times:100]; 

// To repeat forever, use this 
// id repeatAction = [RepeatForever actionWithAction:action]; 

[sprite runAction:repeatAction];