2012-08-08 3 views
0

지나치게 생각하고 있는지 모르겠지만 내 캐릭터가 다른 방향으로 움직이는 경우 표시되는 스프라이트를 조정할 수 있도록 노력하고 있습니다.컨트롤로 선박 애니메이션하기 iOS

예를 들어, 플레이어 손가락이 캐릭터 위의 경우 'moveUp'프레임으로 이동하기를 원합니다. 플레이어의 손가락이 캐릭터 아래에 있다면 'moveDown'프레임으로 이동하고, 그렇지 않으면 'normalState'프레임에 머물러 있습니다.

누군가 내가이 예를 보여줄 수 있습니까? 스프라이트 시트/스프라이트를 구현하는 방법에 대한 좋은 일반 튜토리얼로 안내합니다.

필자는 데모 프로젝트에서 스프라이트 시트를 사용했지만이를 공개하려고하고 있으며 적절하고 성공적인 방법으로 접근하려고합니다.

감사합니다.

답변

1

스프라이트 시트를 이미 만들고 포장 한 것으로 가정합니다 (TexturePacker를 좋아합니다). 내가 atan2을 사용하면 각도에 ​​touchPositionRelativeToPlayer 변환 제안하고에서 프레임을 결정하는 것

...init... 
    //Place all sprite frames from sprite sheet into cache 
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"spriteSheet.png"]; 


    CCSpriteBatchNode *gameBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"spriteSheet.png"]; 
    CCSprite *player = [CCSprite spriteWithSpriteFrameName:@"moveUp"]; 

    [gameBatchNode addChild: player]; 
.... 

- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *aTouch = [touches anyObject]; 

    CGPoint touchPosition = [player.parent convertTouchToNodeSpace:aTouch]; 
    CGPoint touchPositionRelativeToPlayer = ccpSub(touchPosition, player.position); 

    if(touchPositionRelativeToPlayer.y > 0) 
     [player setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"moveUp"]]; 
    else 
     [player setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"moveDown"]]; 
} 

다른 방향하려는 경우 (W에게 등 E, NW를 ..) : 코드는 무언가 같이 될 것입니다.

+0

아 감사합니다. 많은 감사를드립니다. – Lagoo87

관련 문제