cocos2d - x 1 그림 다 프레임 으로 현재 프레임 의 해결 방안 을 얻 습 니 다.
http://blog.csdn.net/xuzhuang2008/article/details/8934645
cocos2d - x 에서 cocostudio 를 사용 하 든 다른 애니메이션 편집기 에서 도 만 든 plist 파일 과 png 파일
그림 다 프레임 방식 으로 애니메이션 재생
cocos2d - x 현재 프레임 을 얻 는 방법 이 없습니다. 나 도 소스 코드 수정 하고 싶 지 않 아.
인터넷 상의 몇 가지 방법 을 참고 하 다
texture 를 가 져 오 는 name 등 다 프레임 이 안 어 울 려 요.
여 기 는 내 가 생각해 낸 방법 이다. 대체적인 사고방식 은 이렇다
프레임 을 프레임 에 넣 을 때 이 프레임 의 좌 표를 저장 합 니 다.
그리고 필요 할 때 sprite 의 display frame 의 개체 Rect 를 얻 으 면 rect 가 2 개 있 습 니 다.
두루 비교 하 다. rect 의 origin. x 와 y 를 통 해 동일 한 지 비교 합 니 다.
여 기 는 구체 적 인 실현 부분 입 니 다.
애니메이션 재생 부분
//
CCRect rects[8];
CCSprite *flowSprite;
CCAnimate *animate;
CCSpriteFrame *frame1;
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("texiao0.plist","texiao0.png");
CCArray*frames=CCArray::create();
char pngName[20];
// i
for (int i=0;i<8; i++) {
sprintf(pngName, "fire\\hotwindg%02d.png",i+1);
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pngName);
CCRect rec1 = frame->getRect();
rects[i] = rec1;
frames->addObject(frame);
}
// CCAnimation
CCAnimation* animation =CCAnimation::createWithSpriteFrames(frames,0.06f);
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,"aa");
CCAnimationCache * aniCache = CCAnimationCache::sharedAnimationCache();
CCAnimation* normal = aniCache->animationByName("aa");
frames->release();
animate = CCAnimate::create(normal);
CCFiniteTimeAction *seq = CCSequence::create(animate,NULL);
flowSprite = CCSprite::create();
animate->setTag(20);
flowSprite->autorelease();
frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("fire\\hotwindg01.png");
flowSprite->setDisplayFrame(frame1);
flowSprite->setScale(0.3f);
addChild(flowSprite,160);
flowSprite->runAction(CCRepeatForever::create(animate));
flowSprite->setPosition(ccp(200,200));
CCLog("%d",animate->getAnimation()->getFrames()->count());
획득 부분
int currentAnimIndex = 0;
const float EPSINON = 0.000001f;
int count = 8;
for(int i = 0; i < count; i++)
{
CCRect rect2 = flowSprite->displayFrame()->getRect();
float y = rect2.origin.y - rects[i].origin.y ;
float x = rect2.origin.x - rects[i].origin.x ;
if (((x >= - EPSINON) && (x <= EPSINON)) && ((y >= - EPSINON) && (y <= EPSINON))){
// i , 1 +1
currentAnimIndex = i+1;
}
}
CCLog("current frame is %d",currentAnimIndex);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.