cocos2d - x 1 그림 다 프레임 으로 현재 프레임 의 해결 방안 을 얻 습 니 다.

2749 단어
이 글 을 남 겨 두 십시오:
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);

좋은 웹페이지 즐겨찾기