Programming/Programming
[cocos2d] Sprite Animation
hurderella
2013. 9. 20. 11:21
반응형
오늘의 작은 목표
- 스프라이트 달리기
달성! ㅋㅋ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | //CCTexture2D를 이용해 이미지 캐쉬 CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(xxx.png); // 애니메이션에서 사용할 프레임들(1에서 n까지)을 로드. //CCTexture2D 와 CCSpriteFrame 은 autorelease 객체이므로 메모리는 신경은 쓰지말고 CCSpriteFrame *frame1 = CCSpriteFrame::createWithTexture(texture, CCRectMake(x*1, y*0, x, y)); ... CCSpriteFrame *frame-n = CCSpriteFrame::createWithTexture(texture, CCRectMake(x*n, y*0, x, y)); // 애니메이션 하기 위해 로드한 프레임들을 Array로 구성 CCArray* animFrames = CCArray::createWithCapacity(n); animFrames->addObject(frame1); ... animFrames->addObject(frame-n); // 애니메이션 Array를 바탕으로 CCAnimation 생성. 인터벌 간격을 인자로 입력 // CCAnimation을 이용해서 CCAnimate 생성. 왜 animation과 animate가 나뉘어져 있는 지 모르겠군 // CCSequence를 형성하기 위해선 CCAnimate가 필요하고..(사실 상속계층 타고 올라가면 더 나오지만..) CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2f); CCAnimate* animate = CCAnimate::create(animation); CCActionInterval* seq = CCSequence::create( animate, NULL); // sprite 하나. CCSprite* sprite = CCSprite::createWithSpriteFrame(frame1); // add 하고. addChild(sprite); // seq를 인자로 action 진행 sprite->runAction( CCRepeatForever::create( seq ) ); |
내일은 사용가능한 모든 애니메이션 리소스를 뽑아서 모듈로 빼놔야겠다.
반응형